Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: va_arg() question

Reply
Thread Tools

Re: va_arg() question

 
 
Mike Wahler
Guest
Posts: n/a
 
      08-07-2003

<(E-Mail Removed)> wrote in message news:(E-Mail Removed)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



 
Reply With Quote
 
 
 
 
Dave Thompson
Guest
Posts: n/a
 
      08-11-2003
On Thu, 7 Aug 2003 09:37:41 -0700, "Mike Wahler"
<(E-Mail Removed)> wrote:

>
> <(E-Mail Removed)> wrote in message news:(E-Mail Removed)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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
question row filter (more of sql query question) =?Utf-8?B?YW5kcmV3MDA3?= ASP .Net 2 10-06-2005 01:07 PM
Quick Question - Newby Question =?Utf-8?B?UnlhbiBTbWl0aA==?= ASP .Net 4 02-16-2005 11:59 AM
Question on Transcender Question :-) eddiec MCSE 6 05-20-2004 06:59 AM
Question re: features of the 831 router (also a 924 question) Wayne Cisco 0 03-02-2004 07:57 PM
Syntax Question - Novice Question sean ASP .Net 1 10-20-2003 12:18 PM



Advertisments