Forums > Dev

instance creation function problem?

August 21, 2007 | 5:54 pm

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


August 21, 2007 | 10:15 pm

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


August 21, 2007 | 10:47 pm

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
>
>


August 21, 2007 | 10:54 pm

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


August 21, 2007 | 11:21 pm

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
>


August 21, 2007 | 11:58 pm

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


August 22, 2007 | 12:07 am

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
>
>


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