Topic: Can one pass a va_list to a function?


Author: Chris.omitthisbit.Brown@arm.andthisbit.com
Date: 1998/12/03
Raw View
In article <RVerlinde-ya02408000R0212982023430001@news.bart.nl>,
Reinder <RVerlinde@alva-bv.nl> wrote:
>
>Hi,
>
>is this legal C/C++?
>
>    #include "all needed headers.h"
>
>    void handle_args( va_list args);
>    void main( char *name, ...);
>
>    void main( char *name, ...)

Don't know about C++, but this is not legal C. main returns int and is
not variadic (unless your compiler is a freestanding implementation).

In answer to your broader question, yes, you can pass a va_list to a
function. There are examples of such in stdio.h.
--
/*  _  */main(int k,char**n){char*i=k&1?"+L*;99,RU[,RUo+BeKAA+BECACJ+CAACA"
/* / ` */"CD+LBCACJ*":1[n],j,l=!k,m;do for(m=*i-48,j=l?m/k:m%k;m>>7?k=1<<m+
/* |   */8,!l&&puts(&l)**&l:j--;printf("  \0_/"+l));while((l^=3)||l[++i]);}
/* \_,hris Brown -- All opinions expressed are probably wrong. */



[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: RVerlinde@alva-bv.nl (Reinder)
Date: 1998/12/02
Raw View
Hi,

is this legal C/C++?

    #include "all needed headers.h"

    void handle_args( va_list args);
    void main( char *name, ...);

    void main( char *name, ...)
    {
        va_list  args;
        va_start( args, name);

            handle_args( args);

        va_end( args);
    }

- If so, can handle_args pass the va_list on to another function?
    - If so, can handle_args pass the va_list to multiple functions?
    - If so, can handle_args be recursive?
- If not, what are the chances that a compiler will handle it OK?

--
Reinder Verlinde


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Ben Pfaff <pfaffben@pilot.msu.edu>
Date: 1998/12/02
Raw View
RVerlinde@alva-bv.nl (Reinder) writes:

   is this legal C/C++?

There is no language C/C++.

       void main( char *name, ...)

main does not return void.  main must have exactly one of the
following signatures:

 int main (void)
 int main (int argc, char *argv[])

or their equivalent.  See C-FAQ 11.12 for more details.


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: "Andrei Alexandrescu" <alexandrescua@micromodeling.com>
Date: 1998/12/02
Raw View
Reinder wrote in message ...

>Hi,

>is this legal C/C++?

>    #include "all needed headers.h"
>
>    void handle_args( va_list args);
>    void main( char *name, ...);
>
>    void main( char *name, ...)
>    {
>        va_list  args;
>        va_start( args, name);
>
>            handle_args( args);
>
>        va_end( args);
>    }


Yes, and it's actually used in vsprintf().

Andrei




[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]