tlbuild: Declarations and definitions
8.1 Declarations and definitions
================================
C standards
...........
The TeX Live build system no longer supports pre-ANSI C compilers. Thus
all function prototypes and definitions must conform to the ANSI C
standard (including 'void' in the declaration of C functions with no
parameters). On the other hand, TL is built for a wide variety of
systems, not all of which support the C99 standard. Therefore using C99
features should be avoided if that can easily be done. In particular, C
code must not contain declarations after statements or C++-style
comments.
If some C99 (or later) constructs must be used, the module should
verify that they are available and otherwise provide an alternative.
For example, the module 'texk/chktex' uses the C99 function 'stpcpy()'
that may or may not be available on a particular system. It uses
'AC_CHECK_DECLS([stpcpy])' in 'configure.ac' to test this, and provides
a perhaps less efficient alternative (in the file 'Utility.h'):
#if !(defined HAVE_DECL_STPCPY && HAVE_DECL_STPCPY)
static inline char *stpcpy(char *dest, const char *src)
{
return strcpy(dest, src) + strlen(src);
}
#endif
Static functions
................
Functions used in only one file should be declared 'static'; they
require no prototype except in forward declarations.
Extern functions
................
Functions not declared 'static', usually because they are used in
several files, require an ('extern') prototype in exactly one header
file, which is included in the file defining the function and in all
files using that function--this is the only way to guarantee consistency
between definition and use. There should be no 'extern' declarations
sprinkled throughout the C code (with or without comments as to where
that function is defined).
Variable declarations
.....................
The declaration of global variables follows analogous rules: they are
either declared 'static' if used in only one file or declared 'extern'
in exactly one header and instantiated in exactly one file.