VC++ Warnings about t_atoms

Dec 29, 2010 at 8:32am

VC++ Warnings about t_atoms

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.

#54149
Dec 29, 2010 at 12:11pm

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

#194834
Dec 29, 2010 at 5:01pm

Hello Oblitteraa,

“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.”

Yep, ++ ; and IMHO then read carefully the API to understand his kind of OOP approach ;
for exemple :

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

Best to use ‘atom_getlong ( )’ instead of …

#194835
Dec 29, 2010 at 7:30pm

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.

#194836

You must be logged in to reply to this topic.