Re: va_arg() question

Discussion in 'C Programming' started by Mike Wahler, Aug 7, 2003.

  1. Mike Wahler

    Mike Wahler Guest

    <> wrote in message news:1.net...
    > 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* ???


    Think about it. How does 'printf()' know? The
    caller *tells* it with format specifiers (e.g.
    %d for int, etc.). You'll need to devise a similar
    'code' to pass this information to your variadic
    function. This could be 'specifiers' contained in
    an additional argument (must be the first) such as those
    of 'printf()', or if each argument always has the
    same type, it would be implied by the order of
    the arguments.


    -Mike
    Mike Wahler, Aug 7, 2003
    #1
    1. Advertising

  2. On Thu, 7 Aug 2003 09:37:41 -0700, "Mike Wahler"
    <> wrote:

    >
    > <> wrote in message news:1.net...
    > > 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() ????

    <snip>
    > Think about it. How does 'printf()' know? The
    > caller *tells* it with format specifiers (e.g.
    > %d for int, etc.). You'll need to devise a similar
    > 'code' to pass this information to your variadic
    > function. This could be 'specifiers' contained in
    > an additional argument (must be the first) such as those
    > of 'printf()', or if each argument always has the
    > same type, it would be implied by the order of
    > the arguments.


    Not necessarily first. Each vararg's type must be determined by
    information preceding it in the argument list; if you want to specify
    all by a single argument, like the *printf/scanf format strings, it
    must precede all varargs and hence must be in the fixed part of the
    argument list, but that can be more than one argument.

    - David.Thompson1 at worldnet.att.net
    Dave Thompson, Aug 11, 2003
    #2
    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:
    394
    Gordon Burditt
    Aug 7, 2003
  2. Eric Sosman

    Re: va_arg() question

    Eric Sosman, Aug 7, 2003, in forum: C Programming
    Replies:
    1
    Views:
    480
    Kevin Easton
    Aug 8, 2003
  3. Artie Gold

    Re: va_arg() question

    Artie Gold, Aug 7, 2003, in forum: C Programming
    Replies:
    0
    Views:
    405
    Artie Gold
    Aug 7, 2003
  4. mdh

    va_arg question

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

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

Share This Page