Forums > MaxMSP

VC++ Warnings about t_atoms

December 29, 2010 | 8:32 am

Hi there. I’m learning how to write my own externals. I’m successfully writing my own functioning objects at this point, but I’m concerned that I’m not using the data types quite right. Here’s a Warning message I get when I build.

————————————————————————-
warning C4047: ‘function’ : ‘t_atom *’ differs in levels of indirection from ‘t_atom (*)[2]‘
————————————————————————-

here’s the function where this occurs

————————————————————————-
void minimum_list(t_minimum *x, t_symbol *s, short ac, t_atom *av)
{
short i;
t_atom listOut[2];
long numbers[2];

numbers[0]=av[0].a_w.w_long;
numbers[1]=av[1].a_w.w_long;

for(i=0;i<2;i++)
{
SETLONG(listOut+i,numbers[i]);
}

outlet_list(x->m_ob.o_outlet,0L,2,&listOut);
}
————————————————————————-

Not sure what it’s warning me about..also I don’t really understand why I have too go like this "listOut+i" instead of "listOut[i]". But it works.


December 29, 2010 | 12:11 pm

Hi.

The quick explaination is that pointers and arrays are almost the same thing in C – namely, an array can actually be seen as a pointer to its first element. So listOut is the same as &listOut[0], listOut+i is the same as &listOut[i] and the type for each of them is t_atom*. As a consequence, the type for &listOut is t_atom**, which is not what outlet_list wants.

In fact the matter is complex, and dealing successfully with the Max API requires quite a deep understanding of C pointers. So, my suggestion is to take a good C textbook (there’s plenty of links in the forum) and study carefully everything about pointers and arrays.

Finally, questions about coding C externals should be posted on the Dev forum – you have more chances of getting a quick reply!

Best
aa


December 29, 2010 | 7:30 pm

Thanks guys. I think I see what andrea means. t_atoms is already a pointer, and it becomes a pointer to a pointer the way it’s used. Maybe I do need a refresher on pointers. I’ve read lots of C programming books…just a little rusty maybe.

I’ll take a good read through the manual too.


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