Shop OBEX P1 Docs P2 Docs Learn Events
Methods with flexible numbers of parameters — Parallax Forums

Methods with flexible numbers of parameters

pjvpjv Posts: 1,903
edited 2013-06-20 15:33 in Propeller 1
Hi All;

If I recall correctly, several years ago there was a thread about a process that permitted a method to be called with a varying number of parameters. In other words, the number of parameters passes to the method was not required to be a static quantity.

I have a need for such an approach, and do not recall what the trick was. Does anyone recall the thread or the process ?

Thanks in advance.

Cheers,

Peter (pjv)

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2013-06-20 13:35
    Spin doesn't like overt parameter mismatches. But there's no reason you can't pass the address of a long array and put your parameters there.

    -Phil
  • pjvpjv Posts: 1,903
    edited 2013-06-20 15:17
    Hi Phil;

    Thanks..... that's what I'm doing now. I was hoping to do it without the time consuming intermediate step of saving into an array.

    I'm pretty sure someone (maybe Jazzed) showed us a way. So I'm still hoping for that revelation.

    Cheers,

    Peter (pjv)
  • Mike GreenMike Green Posts: 23,101
    edited 2013-06-20 15:33
    I really don't recommend this because it involves "cheating". Neither the Spin interpreter, the compilers, nor the structure of the bytecodes are designed for this. I suggest you pass dummy parameters and supply something like zero as their value. This is useful if you're otherwise passing addresses. You could also use -1 since both -1 and zero are encoded very compactly in the Spin bytecodes.
Sign In or Register to comment.