instance creation function problem?

Aug 21, 2007 at 5:54pm

instance creation function problem?

Hello everybody,

I just realized (after hours of isolating it) that there seems to be a problem with the instance creation function if 3 floats are to be used as init args. See the following example, which works fine if you remove val3 and the corresponding A_DEFFLOAT in the steup call:

#include “ext.h”

void *goofy_class;

typedef struct _goofy {
t_object obj;
} t_goofy;

void* goofy_new(double val1, double val2, double val3)
{
t_goofy *x = (t_goofy *)newobject(goofy_class);
post(“val1 = %lf”, val1);
post(“val2 = %lf”, val2);
post(“val3 = %lf”, val3);
return (x);
}

int main(void)
{
setup((t_messlist **)&goofy_class, (method)goofy_new, (method)0L, (short)sizeof(t_goofy), 0L, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
return 0;
}

What am I missing here? (1.42 GHz G4 Mac mini, OS X 10.4.10, Xcode 2.4.1, MaxMSP 4.6.3, UB SDK just downloaded)

Best regards,

Gerhard

#33354
Aug 21, 2007 at 10:15pm

I forgot to add what the problem is :-)

The values posted by goofy_new are not the ones passed to a new instance (but some crazily large numbers, which don’t vary with what is passed)

Hope anybody has an idea.

Best,

Gerhard

#111016
Aug 21, 2007 at 10:47pm

Use A_GIMME instead?

jb

Am 22.08.2007 um 00:15 schrieb Gerhard Eckel:

>
> I forgot to add what the problem is :-)
>
> The values posted by goofy_new are not the ones passed to a new
> instance (but some crazily large numbers, which don’t vary with
> what is passed)
>
> Hope anybody has an idea.
>
> Best,
>
> Gerhard
>
>

#111017
Aug 21, 2007 at 10:54pm

Oh, ja. Good idea. I’ll try that. But shouldn’t it work the way I wrote it? Am I missing something here?

Gerhard

Jeremy Bernstein wrote on Tue, 21 August 2007 16:47
> Use A_GIMME instead?
>
> jb

#111018
Aug 21, 2007 at 11:21pm

Well, your function is accepting doubles but declaring floats… I’ll
bet that it all makes sense if you look at the assembly, but my guess
is that due to some packing foobage, your function works fine when
passing only two args, but when you start passing more the compiler
implements that on the stack rather than in registers or something, it
may have to do with the way Max dispatches your function.

What happens when you do:

void* goofy_new(float val1, float val2, float val3) ?

_Mark

On Aug 21, 2007, at 3:54 PM, Gerhard Eckel wrote:

>
> Oh, ja. Good idea. I’ll try that. But shouldn’t it work the way I
> wrote it? Am I missing something here?
>
> Gerhard
>
> Jeremy Bernstein wrote on Tue, 21 August 2007 16:47
>> Use A_GIMME instead?
>>
>> jb
>

#111019
Aug 21, 2007 at 11:58pm

Mark Pauley wrote on Tue, 21 August 2007 17:21
> What happens when you do:
>
> void* goofy_new(float val1, float val2, float val3) ?

Doesn’t make a difference :-(

Gerhard

#111020
Aug 22, 2007 at 12:07am

I believe that there’s a known issue with 3+ float args with message
definitions. A search of the forum for “Castine A_FLOAT” should turn
up numerous references. Really, just use A_GIMME and avoid the hassle.

jb

Am 22.08.2007 um 01:58 schrieb Gerhard Eckel:

>
> Mark Pauley wrote on Tue, 21 August 2007 17:21
>> What happens when you do:
>>
>> void* goofy_new(float val1, float val2, float val3) ?
>
> Doesn’t make a difference :-(
>
> Gerhard
>
>

#111021

You must be logged in to reply to this topic.