[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: _AC_PROG_CXX_EXIT_DECLARATION: don't `#include <stdlib.h>'
From: |
Paul Eggert |
Subject: |
Re: _AC_PROG_CXX_EXIT_DECLARATION: don't `#include <stdlib.h>' |
Date: |
22 May 2003 13:07:27 -0700 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 |
Jim Meyering <address@hidden> writes:
> This change makes it so that when running configure with e.g., CC=aCC,
> you'll now get this in confdefs.h:
>
> #ifdef __cplusplus
> extern "C" void exit (int);
> #endif
>
> rather than this:
>
> #ifdef __cplusplus
> #include <stdlib.h>
> #endif
Thanks for looking into this. While we're on this subject I have
three related questions.
First, why is the "#ifdef __cplusplus" needed at all? Since the test
is done without "#ifdef __cplusplus", I don't see why the confdefs.h
code has it.
Second, this code:
_AC_COMPILE_IFELSE([AC_LANG_PROGRAM(address@hidden:@include <stdlib.h>
$ac_declaration],
seems backwards to me. $ac_declaration should appear before <stdlib.h>
in the test, since that's how the actual code will do things.
Third, the current Autoconf code does not work with pedantic C99,
which (like C++) requires that functions must be declared before they
are used.
How about the following revised patch instead?
2003-05-22 Jim Meyering <address@hidden>
and Paul Eggert <address@hidden>
* lib/autoconf/c.m4 (_AC_PROG_C_EXIT_DECLARATION):
Renamed from _AC_PROG_CXX_EXIT_DECLARATION, since it applies
to C99 as well as to C++. Remove `#include <stdlib.h>' from
the list; we should never make confdefs.h include <stdlib.h>
or <cstdlib>, because the resulting namespace pollution would
cause other tests to fail. Configure scripts run with some
older versions of g++ and HP's aCC would fail due to such an
#include. Problems reported by Matthew Mueller in
<http://bugs.debian.org/120704> and by Keith Bostic in
<http://mail.gnu.org/archive/html/autoconf/2003-05/msg00063.html>.
Prefer 'void exit (int);' to nothing, since it's required
by C99 (and strictly speaking is necessary even for C89).
Remove '#ifdef __cplusplus' from confdefs.h, since the code
is not specific to C++.
--- lib/autoconf/c.m4.~1.178.~ Thu May 22 12:09:14 2003
+++ lib/autoconf/c.m4 Thu May 22 12:57:52 2003
@@ -476,7 +476,7 @@ _AC_PROG_CC_STDC
_AC_COMPILE_IFELSE(address@hidden:@ifndef __cplusplus
choke me
@%:@endif],
- [_AC_PROG_CXX_EXIT_DECLARATION])
+ [_AC_PROG_C_EXIT_DECLARATION])
AC_LANG_POP(C)dnl
])# AC_PROG_CC
@@ -685,7 +685,7 @@ m4_expand_once([_AC_COMPILER_OBJEXT])[]d
_AC_LANG_COMPILER_GNU
GXX=`test $ac_compiler_gnu = yes && echo yes`
_AC_PROG_CXX_G
-_AC_PROG_CXX_EXIT_DECLARATION
+_AC_PROG_C_EXIT_DECLARATION
AC_LANG_POP(C++)dnl
])# AC_PROG_CXX
@@ -721,21 +721,20 @@ fi[]dnl
])# _AC_PROG_CXX_G
-# _AC_PROG_CXX_EXIT_DECLARATION
+# _AC_PROG_C_EXIT_DECLARATION
# -----------------------------
# Find a valid prototype for exit and declare it in confdefs.h.
-m4_define([_AC_PROG_CXX_EXIT_DECLARATION],
+m4_define([_AC_PROG_C_EXIT_DECLARATION],
[for ac_declaration in \
- ''\
- '#include <stdlib.h>' \
+ 'void exit (int);' \
'extern "C" void std::exit (int) throw (); using std::exit;' \
'extern "C" void std::exit (int); using std::exit;' \
'extern "C" void exit (int) throw ();' \
'extern "C" void exit (int);' \
- 'void exit (int);'
+ ''
do
- _AC_COMPILE_IFELSE([AC_LANG_PROGRAM(address@hidden:@include <stdlib.h>
-$ac_declaration],
+ _AC_COMPILE_IFELSE([AC_LANG_PROGRAM(address@hidden
address@hidden:@include <stdlib.h>],
[exit (42);])],
[],
[continue])
@@ -745,11 +744,9 @@ $ac_declaration],
done
rm -f conftest*
if test -n "$ac_declaration"; then
- echo '#ifdef __cplusplus' >>confdefs.h
echo $ac_declaration >>confdefs.h
- echo '#endif' >>confdefs.h
fi
-])# _AC_PROG_CXX_EXIT_DECLARATION
+])# _AC_PROG_C_EXIT_DECLARATION