Russ Allbery <[EMAIL PROTECTED]> writes:

| The autoconf documentation has this to say about the standard C headers:
|
|      On systems without ANSI C headers, there is so much variation that
|      it is probably easier to declare the functions you use than to
|      figure out exactly what the system header files declare.  Some
|      systems contain a mix of functions ANSI and BSD; some are mostly
|      ANSI but lack `memmove'; some define the BSD functions as macros in
|      `string.h' or `strings.h'; some have only the BSD functions but
|      `string.h'; some declare the memory functions in `memory.h', some
|      in `string.h'; etc.  It is probably sufficient to check for one
|      string function and one memory function; if the library has the
|      ANSI versions of those then it probably has most of the others.
|      If you put the following in `configure.in':
|
|           AC_HEADER_STDC
|           AC_CHECK_FUNCS(strchr memcpy)
|
|      then, in your code, you can put declarations like this:
|
|           #if STDC_HEADERS
|           # include <string.h>
|           #else
|           # ifndef HAVE_STRCHR
|           #  define strchr index
|           #  define strrchr rindex
|           # endif
|           char *strchr (), *strrchr ();
|           # ifndef HAVE_MEMCPY
|           #  define memcpy(d, s, n) bcopy ((s), (d), (n))
|           #  define memmove(d, s, n) bcopy ((s), (d), (n))
|           # endif
|           #endif
|
| But autoconf itself doesn't do this; it instead goes to some lengths to
| track down the appropriate headers and include them rather than using its
| own prototypes.  For example, see ac_include_default in acgeneral.m4.
|
| Which is the right way of doing it?

IMHO, using the right headers is best, because then you'll get full
prototypes on decent systems.  For functions that return pointers or types
like size_t, off_t, etc., you should also include a configure-time check
for a declaration of the function (to accommodate systems that lack the
declaration), and put something like this in your code:

#ifndef HAVE_DECL_MALLOC
"this configure-time declaration test was not run"
#endif
#if !HAVE_DECL_MALLOC
char *malloc ();
#endif

The only problem is that the easiest way to include an autoconf test for
a function declaration is to use the latest (still no official release)
version of autoconf.  Of course, you might be able to swipe the code and
put it in your autoconf-2.12-compatible aclocal.m4 or m4/ directory --
or (easier), just use the declaration-check macro from a package like gcc.

Reply via email to