Tuesday, November 2, 2010

The __P() macro

extern void _sig_ign __P ((int sig)); Understood as _sig_ign for function name, the macro definition __P ().

For example: # define __P (s) s and then compile the results of the above statement as extern void _sig_ign (int sig); this can be done by the macro control this function argument types, if: # define __P (s) (void) then this function becomes no parameters. P is the meaning of the parameter.

Extern void _sig_ign __P ((int sig)); this way is a relatively universal programming style, you can google it __P, will find many similar to that of function declarations, C library inside many functions so declared is due mainly to the ANSI C before the old compiler does not support the function prototype definition, use "__P macro" to ANSI and non-ANSI compiler provides a portable package. Its definition is usually as follows:
# if defined (__STDC__) || Defined (__GNUC__)
# define __P (x) x
# else # define __P (x) ()
# endif
This ANSIC's compiler will compile the sentence as extern void _sig_ign (int sig); non-ANSI C compiler will compile as extern void _sig_ign (); will not be an error, this makes under different compilers can use to increase the portability of the code.

No comments:

Post a Comment