Re: va_arg() question

Discussion in 'C Programming' started by Artie Gold, Aug 7, 2003.

  1. Artie Gold

    Artie Gold Guest

    wrote:
    > Hello all,
    >
    > I have a quick question regarding the use of va_arg() with multiple
    > parameter definitions. If the parameters are of different types, how
    > do I know what type it is when using va_arg() ????
    >
    > For example, if I was to write a function similar to the good old
    > printf() which takes multiple parameters of different types (eg. int,
    > char*, etc) how do I know whether the parameter I'm processing is an
    > int or a char* ???
    >

    The same way printf() does. ;-)

    When you supply a format to printf(), it parses it to see what type of
    variable(s) to expect.

    For example, if you write

    int i = 3;
    char * name_of_i = "i";
    printf("the value of %s is %d", name_of_i, i);

    the first directive it sees is `%s', so it takes the second argument to
    be a pointer to char. Then it sees `%d' and takes the third argument to
    be an int.

    While you can use any method you want, any variadic function needs some
    way of knowing what type(s) of variable(s) to expect.

    HTH,
    --ag




    --
    Artie Gold -- Austin, Texas
     
    Artie Gold, Aug 7, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gordon Burditt

    Re: va_arg() question

    Gordon Burditt, Aug 7, 2003, in forum: C Programming
    Replies:
    0
    Views:
    414
    Gordon Burditt
    Aug 7, 2003
  2. Eric Sosman

    Re: va_arg() question

    Eric Sosman, Aug 7, 2003, in forum: C Programming
    Replies:
    1
    Views:
    516
    Kevin Easton
    Aug 8, 2003
  3. Mike Wahler

    Re: va_arg() question

    Mike Wahler, Aug 7, 2003, in forum: C Programming
    Replies:
    1
    Views:
    409
    Dave Thompson
    Aug 11, 2003
  4. mdh

    va_arg question

    mdh, Sep 11, 2008, in forum: C Programming
    Replies:
    5
    Views:
    388
    Nick Keighley
    Sep 12, 2008
  5. va_arg() question

    , Jul 31, 2013, in forum: C Programming
    Replies:
    2
    Views:
    225
    James Kuyper
    Jul 31, 2013
Loading...

Share This Page