Thread: va_list times 2!

  1. #1
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708

    va_list times 2!

    Are multiple variable argument lists possible?

    That is if I have a function that already takes a variable argument list, can I extend this to take an additional list? I keep thinking I can set-up the second one so that it begins when I set the last parameter of the first list to "NULL", so that being called it would look like:

    double_list_func( VA1a, VA1b, VA1c, NULL, VA2a, VA2b, VA2c, NULL);

    //Whereas first "NULL" stops the first list and initiates the second and the last "NULL" stops the second list...
    Last edited by Sebastiani; 09-15-2001 at 07:45 AM.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    Haven't we done this before????

    Code:
    #include <stdio.h>
    #include <stdarg.h>
    
    void foo ( int x, ... ) {
        va_list ap;
        char *p;
        va_start( ap, x );
        while ( (p=va_arg(ap,char*)) != NULL ) {
            printf( "%s ", p );
        }
        printf( "\n" );
        while ( (p=va_arg(ap,char*)) != NULL ) {
            printf( "%s ", p );
        }
        printf( "\n" );
        va_end(ap);
    }
    
    int main ( ) {
        foo( 1, "hello", "world", NULL, "how", "are", "you", NULL );
        return 0;
    }
    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
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    You are kidding me! All this time I have been trying to do this by creating a new va_list variable!!! Arghh!!! Thanks again, Salem. And by the way, sometimes your memory is just too good!
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Times function for rational numbers
    By CaliJoe in forum C++ Programming
    Replies: 1
    Last Post: 05-01-2009, 04:09 PM
  2. Something about probablility
    By mike_g in forum A Brief History of Cprogramming.com
    Replies: 116
    Last Post: 03-13-2008, 05:33 PM
  3. arrays with elements
    By bradleyd in forum C Programming
    Replies: 5
    Last Post: 04-10-2007, 12:00 PM
  4. how can I re-sort a map
    By indigo0086 in forum C++ Programming
    Replies: 8
    Last Post: 06-01-2006, 06:21 AM
  5. Fastest STL container?
    By Shakti in forum C++ Programming
    Replies: 18
    Last Post: 02-17-2006, 02:07 AM