C-question about stdio.h

C-question about stdio.h

Post by Peter Nobe » Tue, 18 Aug 1998 04:00:00



Hi,

i just stumbled on my first problem in the C-programming area of
Linux...

Having a look inside stdio.h i saw f.i.

extern int fprintf __P((FILE*, __const char* format, ...));

Some questions...

1. what's __P
2. (( )) means reference is to a function, not to a macro...  Right?
3. any special meaning for the two underscores in __const?
4. where's the definition of fprintf... In libc?

Peter Nobels, Roularta Media Group.
Anti-Spam : Remove NoSpam to reply

 
 
 

C-question about stdio.h

Post by Andreas Jaege » Tue, 18 Aug 1998 04:00:00


Quote:>>>>> Peter Nobels writes:

 > Hi,
 > i just stumbled on my first problem in the C-programming area of
 > Linux...

 > Having a look inside stdio.h i saw f.i.

 > extern int fprintf __P((FILE*, __const char* format, ...));

 > Some questions...

 > 1. what's __P
A macro which enables to use this file with ANSI and Pre-ANSI
compilers (see <sys/cdefs.h>).
 > 2. (( )) means reference is to a function, not to a macro...  Right?
 > 3. any special meaning for the two underscores in __const?
Compatibility (see <sys/cdefs.h>).
 > 4. where's the definition of fprintf... In libc?
fprintf is implemented in libc

Andreas
--



 
 
 

C-question about stdio.h

Post by Sascha Bohnenkam » Fri, 28 Aug 1998 04:00:00


Quote:>extern int fprintf __P((FILE*, __const char* format, ...));

>Some questions...

>1. what's __P

some macro ... IMHO it is defined as
#define __P(a) a
... a do nothing macro

Quote:>2. (( )) means reference is to a function, not to a macro...  Right?

no ... the macro __P expects an parameter, which ist (FILE*,__const char*
format,...)
do not forget it is a macro NOT C :)

Quote:>3. any special meaning for the two underscores in __const?

__.* symbols are normaly thought to be reserved for internal usage ... hands
of friend:)
but in this case its nothing more than const

Quote:>4. where's the definition of fprintf... In libc?

already answered
 
 
 

C-question about stdio.h

Post by David Billing Anders » Fri, 28 Aug 1998 04:00:00




>>extern int fprintf __P((FILE*, __const char* format, ...));

>>Some questions...

>>1. what's __P
>some macro ... IMHO it is defined as
>#define __P(a) a
>... a do nothing macro

Not do nothing at all: such a __P definition turns the declaration into
        extern int fprintf (FILE*, __const char* format, ...);

Some history follows: ignore it if you don't care about the history.

The point of such a macro is to cater to really ancient C compilers
that don't understand ISO/ANSI C function prototypes (or modern
compilers that do) without changing the header itself. Just change
the definition of __P.  

  Since __P begins with __, it is
  in the implementor namespace and no 'legal' user code could use __P
  for anything. So the macro use won't accidentally overide
  or collide with some user expression/or macro.
  (by ISO/ANSI C namespace rules)

Here's the point:

#define __P(a) ()

turns the original macro use into
        extern int fprintf ();
as preprocessor output,
which would be acceptable to even the oldest C compiler.

Quote:>>2. (( )) means reference is to a function, not to a macro...  Right?
>no ... the macro __P expects an parameter, which ist (FILE*,__const char*
>format,...)
>do not forget it is a macro NOT C :)

fprintf is a varargs/stdarg function. In Standard C (ignoring the
proposals for C9X and any support there might
be in gcc) there is no way to do a varargs macro.

The ((stuff,stuff))makes the (stuff,stuff) into a single macro
argument (legal in any C compiler of any age).
It's a traditional trick to allow macros to be used to call
varargs functions (at call sites or, as here, at declarations)