Forums > Dev

problem with function arguments


f.e
May 26, 2008 | 11:04 am

Why

void sdmain_debug(t_sdmain *x, int i)
{
if (!i) debug = 0; else debug = 1;
}

works (i is taken as it should be)

while

void sdmain_mouse (t_sdmain *x, int mx, int my, short but, short ctrl,
short shift, short caps, short alt, short rclick)
{

if ((!but) && (!shift) && (!caps) && (!rclick))
{
identify(x, mx, my);
}

post("mouse : %d %d %d %d %d %d %d %d", mx, my, but, ctrl, shift, caps,
alt, rclick); // for debug only
}

doesn’t ?

I can see in the Max console that it’s giving me the adresses instead of
treating the arguments as they should be. Do i *really* have to do a
bloody int ac, Atom *av thing with

int mx = av[0].a_w.w_long; and so on, while i already know exactly what
kind of arguments i’ll get ?

Best

f.e


f.e chanfrault | aka | personal computer music
>>>>>>> http://www.personal-computer-music.com
>>>>>>> | film soundtracks, sound art, music |


May 26, 2008 | 12:07 pm

Are these methods called directly from the max interface / patcher? If so,
change all of your arguments to long. Max doesn’t deal with int and short,
only long, double, and symbol (for messages). That would explain why the
first method works and the second doesn’t. In the first max would pass a
long which you treat like an int (without casting). If its set to zero, it
would still be zero as an int. In your second method your arguments would be
completely screwed for that reason.

Btw if you do deal with atoms, they’re not that bad once you use the
functions like:

long mx = atom_getlong(av);
long my = atom_getlong(av+1);
etc

Cheers,
Thijs

On Mon, May 26, 2008 at 12:04 PM, f.e

wrote:

> Why
>
> void sdmain_debug(t_sdmain *x, int i)
> {
> if (!i) debug = 0; else debug = 1;
> }
>
> works (i is taken as it should be)
>
> while
>
> void sdmain_mouse (t_sdmain *x, int mx, int my, short but, short ctrl,
> short shift, short caps, short alt, short rclick)
> {
>
> if ((!but) && (!shift) && (!caps) && (!rclick))
> {
> identify(x, mx, my);
> }
>
> post("mouse : %d %d %d %d %d %d %d %d", mx, my, but, ctrl, shift, caps,
> alt, rclick); // for debug only
> }
>
> doesn’t ?
>
> I can see in the Max console that it’s giving me the adresses instead of
> treating the arguments as they should be. Do i *really* have to do a bloody
> int ac, Atom *av thing with
>
> int mx = av[0].a_w.w_long; and so on, while i already know exactly what
> kind of arguments i’ll get ?
>
> Best
>
> f.e
>
> –
> f.e chanfrault | aka | personal computer music
> >>>>>>> http://www.personal-computer-music.com
> >>>>>>> | film soundtracks, sound art, music |
>



f.e
May 28, 2008 | 11:08 am



f.e
May 28, 2008 | 11:46 am


May 28, 2008 | 12:22 pm

f.e wrote:
> I know how to easily deal with this using an ac/av atoms thing, but i
> really want to understand why is it so hard to use arguments you know
> the type and the length in a function.

Because it’s too many of them. I don’t remember correctly, but I think
there is an upper limit of the number of arguments you can use and/or
there is a rule how to order them. I’m not 100% sure how to do it
correctly because in such a case I always use the t_atom to avoid the
trouble.

Olaf



f.e
May 28, 2008 | 12:41 pm


May 28, 2008 | 12:42 pm

On Wed, May 28, 2008 at 1:22 PM, Olaf Matthes

wrote:

> f.e wrote:
>
>> I know how to easily deal with this using an ac/av atoms thing, but i
>> really want to understand why is it so hard to use arguments you know the
>> type and the length in a function.
>>
>
> Because it’s too many of them. I don’t remember correctly, but I think
> there is an upper limit of the number of arguments you can use and/or there
> is a rule how to order them. I’m not 100% sure how to do it correctly
> because in such a case I always use the t_atom to avoid the trouble.
>

You’re right, I think the limit is 7.

> When i set it to
>
> addmess((method) sdmain_mouse, "mouse", A_GIMME, 0);
>
> all values are wrong in the max console…
>
>
Did you change the arguments of your method to : "MyObject *x, t_symbol *s,
long ac, t_atom *av" ? If your data looks wrong in the max console, you’re
probably not parsing the atoms correctly. If you post the code we can
probably help…

Thijs


May 28, 2008 | 2:04 pm

The limit *is* seven.

It’s in the SDK docs and there’s a #define MAXARGS.

Use A_GIMME to support longer parameter lists.


Viewing 8 posts - 1 through 8 (of 8 total)