standards: Standard C

1 
1 3.4 Standard C and Pre-Standard C
1 =================================
1 
1 1989 Standard C is widespread enough now that it is ok to use its
1 features in programs.  There is one exception: do not ever use the
1 "trigraph" feature of Standard C.
1 
1    The 1999 and 2011 editions of Standard C are not fully supported on
1 all platforms.  If you aim to support compilation by compilers other
1 than GCC, you should not require these C features in your programs.  It
1 is ok to use these features conditionally when the compiler supports
1 them.
1 
1    If your program is only meant to compile with GCC, then you can use
1 these features if GCC supports them, when they give substantial benefit.
1 
1    However, it is easy to support pre-standard compilers in most
1 programs, so if you know how to do that, feel free.
1 
1    To support pre-standard C, instead of writing function definitions in
1 standard prototype form,
1 
1      int
1      foo (int x, int y)
1      ...
1 
1 write the definition in pre-standard style like this,
1 
1      int
1      foo (x, y)
1           int x, y;
1      ...
1 
1 and use a separate declaration to specify the argument prototype:
1 
1      int foo (int, int);
1 
1    You need such a declaration anyway, in a header file, to get the
1 benefit of prototypes in all the files where the function is called.
1 And once you have the declaration, you normally lose nothing by writing
1 the function definition in the pre-standard style.
1 
1    This technique does not work for integer types narrower than 'int'.
1 If you think of an argument as being of a type narrower than 'int',
1 declare it as 'int' instead.
1 
1    There are a few special cases where this technique is hard to use.
1 For example, if a function argument needs to hold the system type
1 'dev_t', you run into trouble, because 'dev_t' is shorter than 'int' on
1 some machines; but you cannot use 'int' instead, because 'dev_t' is
1 wider than 'int' on some machines.  There is no type you can safely use
1 on all machines in a non-standard definition.  The only way to support
1 non-standard C and pass such an argument is to check the width of
1 'dev_t' using Autoconf and choose the argument type accordingly.  This
1 may not be worth the trouble.
1 
1    In order to support pre-standard compilers that do not recognize
1 prototypes, you may want to use a preprocessor macro like this:
1 
1      /* Declare the prototype for a general external function.  */
1      #if defined (__STDC__) || defined (WINDOWSNT)
1      #define P_(proto) proto
1      #else
1      #define P_(proto) ()
1      #endif
1