Thread: FreeBSD 5.1, gcc 3.3.3 and va_list

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    52

    FreeBSD 5.1, gcc 3.3.3 and va_list

    I've tried looking around and I couldn't find it anywhere.

    I have some programs I wrote that use va_list (va_start and va_end too obviously) but it says that it is incompatible with this version of gcc and I had to use stdarg.

    I've basically got this...

    Code:
    #ifdef USE_VA_ARGS
        va_list *var;
    #else
        char *p1, *p2, *p3, *p4... *p11;
    #endif
    then using va_start and va_end later or p1 = etc. But there seems to be somewhere where it is carrying over some values from an old pointer somewhere and I cannot for the life of me find out where. The code is way too long to paste and it's like looking for a needle in a haystack. Just wondering if someone could give me some advice, as I don't like using lots and lots of pointers in lots of functions. I don't want to downgrade gcc but it's looking like the only option.

    Any help would be extremely appreciated.

    Thanks
    - Daniel Wallace

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Try writing a small program which has the same problem then
    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.

  3. #3
    SleepWalker tjohnsson's Avatar
    Join Date
    Apr 2004
    Posts
    70
    just include <stdarg.h>
    you can use new variadic functions almost just like the older ones...
    remove va_dcl if you have used it at
    function declarations and va_start takes one more argument more.

    Code:
    void
    my_print ( char *format, ... ) {
        ......
        va_start ( args, format ); // va_list *, (char *) arg. pointer where list reading should begin
        ......
    }
    http://www.linuxselfhelp.com/gnu/gli...34.html#SEC667
    Last edited by tjohnsson; 06-10-2004 at 11:11 PM.

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    52
    Thanks for that.

    Re: Salem...

    I was going to put up a simplified version of it, except I realised my error, it was just sloppyness on my behalf, not initialising the pointers, so it was keeping some old info and such

    Thanks again guys
    - Daniel Wallace

  5. #5
    .
    Join Date
    Nov 2003
    Posts
    307
    For most things, what goes into a header file is agreed upon. FreeBSD does not do the vararg thing in header files the way all the other unixen do.

    See Marc Rockind's 'Advanced Unix Programming' for a complete blow-by-blow discussion of this problem (what Unix supports what level of POSIX or SUS). It's not a trivial one.

  6. #6
    Registered User
    Join Date
    Sep 2002
    Posts
    52
    Thanks for that
    - Daniel Wallace

Popular pages Recent additions subscribe to a feed