|
|
Appropriate use of __STDC__ produces a header file that can be used for both old and new compilers:
header.h:The following function uses prototypes and can still be compiled on an older system:struct s { /* ... */ }; #ifdef __STDC__ void errmsg(int, ...); struct s *f(const char *); int g(void); #else void errmsg(); struct s *f(); int g(); #endif
struct s * #ifdef __STDC__ f(const char *p) #else f(p) char *p; #endif { /* ... */ }The following is an updated source file (as with choice 3 above). The local function still uses an old style definition, but a prototype is included for newer compilers:
source.c:#include <header.h> typedef /* ... */ MyType; #ifdef __STDC__ static void del(MyType *); /* ... */ #endif static void del(p) MyType *p; { /* ... */ } /* ... */