Thread: va_list

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    1

    va_list

    Does anyone know if it's possible to make the assignment:
    var.list = lis; /* See "My program" below */

    gcc 3.4.4 seems to be ok with this assignment, but the Tornado compiler does not. It complains about incompatible types in assignment. This may be using va_list in an unintended way. I've only seen va_list used in one way (see "Standard use of va_arg:").

    Also, does anyone know how va_list is defined? I've seen:

    typedef do-type va_list;

    but what is "do-type"?



    Code:
    My program:
    ----------------------------------------------
    typedef struct someStruct
        {
        SWUInt32  form;
        va_list   list;
        }
      someStruct;
    
    #include <stdarg.h>
    
    int main (void)
    {
       va_list lis;
       someStruct var;
    
       var.list = lis;
    }
    Code:
    Standard use of va_arg:
    ------------------------------------------------
    #include <stdarg.h>
    void va_cat(char *s, ...)
        {
        char *t;
        va_list ap;
    
        va_start(ap, s);
        while (t = va_arg(ap, char *)) null pointer ends list
            {
            s += strlen(s);            skip to end
            strcpy(s, t);              and copy a string
            }
        va_end(ap);
        }

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    va_list is an obscure type. You really shouldn't do anything with a va_list except call the functions in stdarg.h. The compiler can define va_list however it wants, in order to implement the functionality it provides. Consider it a magical type that shouldn't be messed with.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    va_copy() perhaps?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed