Go Down

Topic: Problems with va_start, va_end, and so on (Read 925 times) previous topic - next topic

tigrezno

Hi again,

i'm having problems with functions without an exact number of parameters. This is my code:

Code: [Select]
byte *add_position(const char *fmt, ...) {
   va_list ap;
   int size, index;
   byte *posarray;
   
   size = get_fmt_size(fmt);
   posarray = (byte *)calloc(size, 1);
   
   va_start(ap, fmt);
   for(index=0; index<size; index++) {
       posarray[index] = va_arg(ap, byte);
   }
   va_end(ap);
   
   return posarray;
}


You can see that I use calloc and va_xxx family of functions. I really didn't know i could use them since i saw on Matrix.cpp shipped with arduino distribution. What are all the libraries i can use with arduino? Is it documented?

My problem is compiling that code, it gives the following message:

Code: [Select]
In function `byte* add_position(const char*, ...)':
note: if this code is reached, the program will abort


and "va_start(ap, fmt);" is highlighted.

What's the problem?

mellis

The va_... functions aren't really supported in Arduino - sometimes we do some magic behind the scenes, but I don't know we want to document it for standard use.

tigrezno

Quote
The va_... functions aren't really supported in Arduino - sometimes we do some magic behind the scenes, but I don't know we want to document it for standard use.


and what about using "calloc"?

anything avr-gcc can compile will work in arduino?

mellis

Anything avr-gcc can compile should work in Arduino, yes.  The va_... error you got baffles me, because I would expect it to work.  calloc() should work without any problems, but I'm not sure if I've tried it.

tigrezno

thanks for your quick responses, it's of great help to know it :)

tigrezno

#5
Sep 27, 2007, 12:32 am Last Edit: Sep 27, 2007, 12:33 am by tigrezno Reason: 1
oops i got it, the problem goes out if i comment the for code.

va_start and va_end compile fine, something happens with the for.

edit:

ok, it's the va_arg function. without it all compile nicely.

Go Up