Pages: [1]   Go Down
Author Topic: Problems with va_start, va_end, and so on  (Read 801 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 86
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi again,

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

Code:
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:
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?
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 11
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 86
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 11
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 86
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks for your quick responses, it's of great help to know it smiley
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 86
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: September 26, 2007, 05:33:58 pm by tigrezno » Logged

Pages: [1]   Go Up
Jump to: