468,272 Members | 2,041 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,272 developers. It's quick & easy.

Passing multiple arguments

cypherzero
Some C functions like printf take an unlimited number of arguments of various types.
Does anyone know how such a function is created, stdio.h doesn't give much of a clue, specifying only '...' and not how the values are actually obtained by the function itself.

Thanks in advance.
Sep 3 '07 #1
1 10532
weaknessforcats
9,207 Expert Mod 8TB
Check out the va_arg macros and the ellipsis operator.

The printf() function prototype looks like:

Expand|Select|Wrap|Line Numbers
  1. int printf(const char* arg, ...);
  2.  
The arg string is parsed using macros:

va_list
va_start
va_arg
va_end

The ellipsis (...) is a placeholder for a variable number of arguments.

In the case of printf(), the number of % signs is counted and that tells how many arguments the ellipsis contains.

Just read up on how to use these macros.

It's in the K&R ANSI C Programming Language Prentice Hall 1988.
Sep 3 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by domeceo | last post: by
7 posts views Thread by Harolds | last post: by
7 posts views Thread by John Layton | last post: by
5 posts views Thread by goldtech | last post: by
1 post views Thread by Ben Warren | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.