www.delorie.com/gnu/docs/autoconf/autoconf_64.html   search  
 
Buy the book!


Autoconf

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.10.3 C Compiler Characteristics

The following macros provide ways to find and exercise a C Compiler. There are a few constructs that ought to be avoided, but do not deserve being checked for, since they can easily be worked around.

Don't use lines containing solitary backslashes
They tickle a bug in the HP-UX C compiler (checked on HP-UX 10.20, 11.00, and 11i). Running the compiler on the following source,

 
#ifdef __STDC__
/\
* A comment with backslash-newlines in it. %{ %} *\
\
/
char str[] = "\\
" A string with backslash-newlines in it %{ %} \\
"";
char apostrophe = '\\
\
'\
';
#endif

yields

 
error-->cpp: "foo.c", line 13: error 4048: Non-terminating comment at end of file.
error-->cpp: "foo.c", line 13: error 4033: Missing #endif at end of file.

Removing the lines with solitary backslashes solves the problem.

Don't compile several files at once if output matters to you
Some compilers, such as the HP's, reports the name of the file it is compiling when they are several. For instance:

 
$ cc a.c b.c
a.c:
b.c:

This can cause problems if you observe the output of the compiler to detect failures. Invoking `cc -c a.c -o a.o; cc -c b.c -o b.o; cc a.o b.o -o c' solves the issue.

Macro: AC_PROG_CC ([compiler-search-list])
Determine a C compiler to use. If CC is not already set in the environment, check for gcc and cc, then for other C compilers. Set output variable CC to the name of the compiler found.

This macro may, however, be invoked with an optional first argument which, if specified, must be a space separated list of C compilers to search for. This just gives the user an opportunity to specify an alternative search list for the C compiler. For example, if you didn't like the default order, then you could invoke AC_PROG_CC like this:

 
AC_PROG_CC(cl egcs gcc cc)

If the C compiler is not in ANSI C mode by default, try to add an option to output variable CC to make it so. This macro tries various options that select ANSI C on some system or another. It considers the compiler to be in ANSI C mode if it handles function prototypes correctly.

After calling this macro you can check whether the C compiler has been set to accept ANSI C; if not, the shell variable ac_cv_prog_cc_stdc is set to `no'. If you wrote your source code in ANSI C, you can make an un-ANSIfied copy of it by using the program ansi2knr, which comes with Automake. See also under AC_C_PROTOTYPES below.

If using the GNU C compiler, set shell variable GCC to `yes'. If output variable CFLAGS was not already set, set it to `-g -O2' for the GNU C compiler (`-O2' on systems where GCC does not accept `-g'), or `-g' for other compilers.

Macro: AC_PROG_CC_C_O
If the C compiler does not accept the `-c' and `-o' options simultaneously, define NO_MINUS_C_MINUS_O. This macro actually tests both the compiler found by AC_PROG_CC, and, if different, the first cc in the path. The test fails if one fails. This macro was created for GNU Make to choose the default C compilation rule.

Macro: AC_PROG_CPP
Set output variable CPP to a command that runs the C preprocessor. If `$CC -E' doesn't work, `/lib/cpp' is used. It is only portable to run CPP on files with a `.c' extension.

Some preprocessors don't indicate missing include files by the error status. For such preprocessors an internal variable is set that causes other macros to check the standard error from the preprocessor and consider the test failed if any warnings have been reported.

The following macros check for C compiler or machine architecture features. To check for characteristics not listed here, use AC_COMPILE_IFELSE (see section 6.4 Running the Compiler) or AC_RUN_IFELSE (see section 6.6 Checking Run Time Behavior).

Macro: AC_C_BACKSLASH_A
Define `HAVE_C_BACKSLASH_A' to 1 if the C compiler understands `\a'.

Macro: AC_C_BIGENDIAN ([action-if-true], [action-if-false], [action-if-unknown])
If words are stored with the most significant byte first (like Motorola and SPARC CPUs), execute action-if-true. If words are stored with the least significant byte first (like Intel and VAX CPUs), execute action-if-false.

This macro runs a test-case if endianness cannot be determined from the system header files. When cross-compiling, the test-case is not run but grep'ed for some magic values. action-if-unknown is executed if the latter case fails to determine the byte sex of the host system.

The default for action-if-true is to define `WORDS_BIGENDIAN'. The default for action-if-false is to do nothing. And finally, the default for action-if-unknown is to abort configure and tell the installer which variable he should preset to bypass this test.

Macro: AC_C_CONST
If the C compiler does not fully support the ANSI C qualifier const, define const to be empty. Some C compilers that do not define __STDC__ do support const; some compilers that define __STDC__ do not completely support const. Programs can simply use const as if every C compiler supported it; for those that don't, the `Makefile' or configuration header file will define it as empty.

Occasionally installers use a C++ compiler to compile C code, typically because they lack a C compiler. This causes problems with const, because C and C++ treat const differently. For example:

 
const int foo;

is valid in C but not in C++. These differences unfortunately cannot be papered over by defining const to be empty.

If autoconf detects this situation, it leaves const alone, as this generally yields better results in practice. However, using a C++ compiler to compile C code is not recommended or supported, and installers who run into trouble in this area should get a C compiler like GCC to compile their C code.

Macro: AC_C_VOLATILE
If the C compiler does not understand the keyword volatile, define volatile to be empty. Programs can simply use volatile as if every C compiler supported it; for those that do not, the `Makefile' or configuration header will define it as empty.

If the correctness of your program depends on the semantics of volatile, simply defining it to be empty does, in a sense, break your code. However, given that the compiler does not support volatile, you are at its mercy anyway. At least your program will compile, when it wouldn't before.

In general, the volatile keyword is a feature of ANSI C, so you might expect that volatile is available only when __STDC__ is defined. However, Ultrix 4.3's native compiler does support volatile, but does not defined __STDC__.

Macro: AC_C_INLINE
If the C compiler supports the keyword inline, do nothing. Otherwise define inline to __inline__ or __inline if it accepts one of those, otherwise define inline to be empty.

Macro: AC_C_CHAR_UNSIGNED
If the C type char is unsigned, define __CHAR_UNSIGNED__, unless the C compiler predefines it.

Macro: AC_C_LONG_DOUBLE
If the C compiler supports a working long double type with more range or precision than the double type, define HAVE_LONG_DOUBLE.

Macro: AC_C_STRINGIZE
If the C preprocessor supports the stringizing operator, define HAVE_STRINGIZE. The stringizing operator is `#' and is found in macros such as this:

 
#define x(y) #y

Macro: AC_C_PROTOTYPES
If function prototypes are understood by the compiler (as determined by AC_PROG_CC), define PROTOTYPES and __PROTOTYPES. In the case the compiler does not handle prototypes, you should use ansi2knr, which comes with the Automake distribution, to unprotoize function definitions. For function prototypes, you should first define PARAMS:

 
#ifndef PARAMS
# if PROTOTYPES
#  define PARAMS(protos) protos
# else /* no PROTOTYPES */
#  define PARAMS(protos) ()
# endif /* no PROTOTYPES */
#endif

then use it this way:

 
size_t my_strlen PARAMS ((const char *));

This macro also defines __PROTOTYPES; this is for the benefit of header files that cannot use macros that infringe on user name space.

Macro: AC_PROG_GCC_TRADITIONAL
Add `-traditional' to output variable CC if using the GNU C compiler and ioctl does not work properly without `-traditional'. That usually happens when the fixed header files have not been installed on an old system. Since recent versions of the GNU C compiler fix the header files automatically when installed, this is becoming a less prevalent problem.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003