C++ and object arg problem

Feb 21, 2007 at 11:16pm

C++ and object arg problem

hello,

I am using Xcode 2.4 Max4.6.2 and latest UBSDK

when trying to use C++ for objects i am having a problem with the values being passed to my objects new method.

here is an example that highlight the problem.

if i have an object like this

extern “C” int main(void)
{
setup((t_messlist **)&myobj_class,(method)myobj_new, (method)dsp_free, (short)sizeof(t_myobj), 0L,
A_DEFLONG, A_DEFLONG, A_DEFLOAT, A_DEFFLOAT, 0 );
…..
}

void *myobj_new(long fftsize, long hop, double maxblurtime, double blurtime)
{

post(“%i %i %f %f”, fftsize, hop, maxblurtime, blurtime);
….
}

if i create the object in the patcher as follows.

myobj 1024 256 .6 .3

this prints in the max window

1024 256 0.00000 4294967296.000000

if i reverse the order of args expected to be doubles first i get similar results. anyone else experience this?? any hints?

#30399
Feb 22, 2007 at 5:40am

Looks like you’re getting uninitialized pointers. no idea why, the
code looks OK.

I usually use the more generic A_GIMME form:
void * myobj_new(t_symbol *s, short ac, t_atom *av)

This way you can allow integers in place of floats (with some arg
testing).

On Feb 21, 2007, at 3:16 PM, testcase wrote:

>
> hello,
>
> I am using Xcode 2.4 Max4.6.2 and latest UBSDK
>
> when trying to use C++ for objects i am having a problem with the
> values being passed to my objects new method.
>
> here is an example that highlight the problem.
>
> if i have an object like this
>
> extern “C” int main(void)
> {
> setup((t_messlist **)&myobj_class,(method)myobj_new, (method)
> dsp_free, (short)sizeof(t_myobj), 0L,
> A_DEFLONG, A_DEFLONG, A_DEFLOAT, A_DEFFLOAT, 0 );
> …..
> }
>
> void *myobj_new(long fftsize, long hop, double maxblurtime, double
> blurtime)
> {
>
> post(“%i %i %f %f”, fftsize, hop, maxblurtime, blurtime);
> ….
> }
>
>
> if i create the object in the patcher as follows.
>
> myobj 1024 256 .6 .3
>
> this prints in the max window
>
> 1024 256 0.00000 4294967296.000000
>
> if i reverse the order of args expected to be doubles first i get
> similar results. anyone else experience this?? any hints?
>
>
>

#97080
Feb 22, 2007 at 5:47am

I would definitely go the A_GIMME route. I think there have been some
problems with signatures like A_DEFLONG, A_DEFLONG, A_DEFLOAT,
A_DEFFLOAT. For instance, things worked ok on macintel but not on PPC
when I was working with such functions a few months ago.

wes

On 2/21/07, Graham Wakefield

wrote:
> Looks like you’re getting uninitialized pointers. no idea why, the
> code looks OK.
>
> I usually use the more generic A_GIMME form:
> void * myobj_new(t_symbol *s, short ac, t_atom *av)
>
> This way you can allow integers in place of floats (with some arg
> testing).
>
> On Feb 21, 2007, at 3:16 PM, testcase wrote:
>
> >
> > hello,
> >
> > I am using Xcode 2.4 Max4.6.2 and latest UBSDK
> >
> > when trying to use C++ for objects i am having a problem with the
> > values being passed to my objects new method.
> >
> > here is an example that highlight the problem.
> >
> > if i have an object like this
> >
> > extern “C” int main(void)
> > {
> > setup((t_messlist **)&myobj_class,(method)myobj_new, (method)
> > dsp_free, (short)sizeof(t_myobj), 0L,
> > A_DEFLONG, A_DEFLONG, A_DEFLOAT, A_DEFFLOAT, 0 );
> > …..
> > }
> >
> > void *myobj_new(long fftsize, long hop, double maxblurtime, double
> > blurtime)
> > {
> >
> > post(“%i %i %f %f”, fftsize, hop, maxblurtime, blurtime);
> > ….
> > }
> >
> >
> > if i create the object in the patcher as follows.
> >
> > myobj 1024 256 .6 .3
> >
> > this prints in the max window
> >
> > 1024 256 0.00000 4294967296.000000
> >
> > if i reverse the order of args expected to be doubles first i get
> > similar results. anyone else experience this?? any hints?
> >
> >
> >
>
>

#97081
Feb 22, 2007 at 10:22am

On 22-Feb-2007, at 6:47, Wesley Smith wrote:

> I would definitely go the A_GIMME route. I think there have been some
> problems with signatures like A_DEFLONG, A_DEFLONG, A_DEFLOAT,
> A_DEFFLOAT.

Wes is correct. This has been confirmed on the mail list in the past
by DDZ and JKC. Mixing floats and ints if there are 3 or more
parameters breaks parameter set up. Search the archives for details.

It would be a Good Idea if this could information could find its way
into the SDK documention.

————– http://www.bek.no/~pcastine/Litter/ ————-
Peter Castine +–> Litter Power & Litter Bundle for Jitter
Universal Binaries on the way
iCE: Sequencing, Recording &
Interface Building for |home | chez nous|
Max/MSP Extremely cool |bei uns | i nostri|
http://www.dspaudio.com/ http://www.castine.de

#97082
Feb 22, 2007 at 2:40pm

thanks everyone. i had thought in the past i had mixed floats and ints in more than 3 args and everything worked fine. perhaps i am mistaken. anyway, a very good thing to know and certainly something that should make it into the sdk doc.

#97083

You must be logged in to reply to this topic.