DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Complying with standard C

Examples

Appropriate use of __STDC__ produces a header file that can be used for both old and new compilers:

   header.h:
   

struct s { /* ... */ };

#ifdef __STDC__ void errmsg(int, ...); struct s *f(const char *); int g(void); #else void errmsg(); struct s *f(); int g(); #endif

The following function uses prototypes and can still be compiled on an older system:
   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; { /* ... */ } /* ... */


Next topic: Functions with varying arguments
Previous topic: Mixing considerations

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003