Contents|Index|Previous|Next

Why convert system header files?

The ‘fixincludes’ installation step described here applies only to the native configuration of the GNUPro Toolkit—that is, only if your tape is configured to develop software for the same host on which it runs. If you have a cross-development tape, configured to develop software for another machine (the target), the system header files from your host are not needed for the GNU compilers. Cross-development tapes have ‘target = target’ on the tape label.

For the native configuration, it is very important to run ‘Install fixincludes’ (on each host where you install the compiler binaries).

When the ANSI X3J11 committee finished developing a standard for the C language, a few things that had worked one way in many traditional C compilers ended up working differently in ANSI C. Most of these changes are improvements. But some UNIX header files still rely on the old C meanings, in cases where the UNIX vendor has not yet converted to using an ANSI C compiler for the operating system itself. ‘Install fixincludes’ does a mechanical translation that writes ANSI C versions of some system header files into a new, GCC-specific include directory— your system’s original header files are not affected.

The C header files supplied with SVr4 versions of UNIX depend on a questionable interpretation of the ANSI C standard: they test for a non-ANSI environment by checking whether _ _STDC_ _ is defined as zero. The ANSI standard actually only specifies that _ _STDC_ _ be defined to 1; if it is defined to any other value, the environment is not ANSI C compatible, and ANSI C says nothing about what that value might be.

GCC defines _ _STDC_ _ to 1 when running with ‘-ansi’, when it functions as an “ANSI C superset” compiler. (It also sets _ _STRICT_ANSI_ _ when it runs with the ‘-pedantic’ option.) However, GCC leaves _ _STDC_ _ undefined when it is not running as an ANSI C compiler.

Unfortunately for Solaris users, Solaris header files follow the SVr4 choice. Since GCC never defines _ _STDC_ _ as 0, the distributed header files can leave out some declarations. (Look in ‘/usr/include/time.h’, for example.)

Part of the installation process of the native compiler release is to fix the header files, such as ‘stdio.h’, on the host system to remove ANSI incompatibilities. ‘Install fixincludes’ makes copies of the system ‘include’ files which have these nonstandard features removed, so that GCC can process them. These copies are placed in a new, GCC-specific ‘include’ directory—your system’s original header files are not affected. Once these fixed header files are created, GCC finds and uses them automatically.

Likewise, C++ programmers require C++-ready, ANSI-compatible versions of the standard C header files. These used to be provided with libg++, but were difficult to maintain due to the design compromises (and kludges) that were necessary to make these work on all the systems Cygnus Solutions supports.

Cygnus Solutions has recently introduced what we believe to be a better solution in the form of a new shell script, fixproto. fixproto analyzes all the header files in ‘/usr/include’, and adds any missing standard ANSI and Posix.2 prototypes. The ‘extern “C”’ braces needed to specify that these are C (not C++) functions are also added as needed. It is run as part of the installation and/or build of a native compiler. The resulting header files are also used for C, with the result that the ‘-Wimplicit’ option for GCC is much more useful. The most obvious drawback to this solution is that the process of fixing the ‘include’ files takes longer to run, so any installation of a native compiler is noticeably slower than in previous releases. Performance improvements will be made as part of a future release.

If you don’t run fixincludes, the GNU C compiler can only use the original system header files when you compile new C programs. In some cases, the resulting programs will fail at run-time.