Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

look at these calls closely:

printf("hello, world\n");
printf("%d", 2);
printf("%d%g\n", 2, 2.3);

we see that printf can accept any type and any number of args. however we know that functions in c only take fixed length args and should have a compatible prototype to match the arg. what would be the prototype of printf ?

share|improve this question
if you don't know variadic functions, this question cannot be answered ! – Abhinav Pandey Nov 29 '11 at 12:01
and if you already know variadic functions, why on earth did you post this question? :-/ – Péter Török Nov 29 '11 at 15:15

we know that functions in c only take fixed length args

So you know it incorrectly. printf (and several other standard library functions) use a language feature called variable argument list.

Btw its signature declaration looks more or less like this (may be different on your platform):

int printf ( const char * format, ... );
share|improve this answer
whether you write the "format" or not doesn't matter in function declaration – Abhinav Pandey Nov 29 '11 at 12:34
@AbhinavPandey, at least if readability (by humans) doesn't matter, that is :-) – Péter Török Nov 29 '11 at 12:38
"function signature" really is a C++ term associated with overloading; C doesn't do overloading so it only has a function declaration. – MSalters Nov 29 '11 at 13:08
Wouldn't ommiting format in the declaration make it possible to call printf(1); without even a compiler warning? – user281377 Nov 29 '11 at 13:18
@MSalters, thanks, fixed. – Péter Török Nov 29 '11 at 15:14
extern int printf (__const char *__restrict __format, ...);

The ellipsis indicate that this function uses a variable argument list.

share|improve this answer
Why the leading underscores for const and restrict? Those are perfectly good keywords in C99, and the right ones for the function declaration. (__format is a reserved identifier, but may be correct for a particular implementation.) – David Thornley Nov 29 '11 at 15:21
Because the declaration is copied-and-pasted from the GNU C Library version of stdio.h. – dan04 Nov 29 '11 at 15:45
Dan04: exactly. Lazy me ;-) – user281377 Nov 29 '11 at 22:41
@dan04: Using __const and __restrict makes it possible to use the same header file in both C89 and C99 modes. A proper C89 compiler must work with correctly on a program that starts with #define restrict 12345 before its #include <stdio.h> but would not be required to work correctly if the program started with #define __restrict 12345. – supercat Aug 1 '15 at 20:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.