470,607 Members | 2,467 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Passing multiple arguments

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 10625
9,208 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, ...);
The arg string is parsed using macros:


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
By using this site, you agree to our Privacy Policy and Terms of Use.