[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: Jim Meyering
Subject: Re: _AC_PROG_CXX_EXIT_DECLARATION: don't `#include <stdlib.h>'
Date: Fri, 23 May 2003 00:18:35 +0200

Paul Eggert <address@hidden> wrote:
> 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.

Hi Paul!

> 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.

Your question suggests that this macro deserves more comments :-)

First, that macro is only run when testing a C++ compiler.
That can happen either via AC_PROG_CXX or via AC_PROG_CC when
CC has been explicitly set to a C++ compiler.

I think the goal is that confdefs.h/config.h be usable as input to both
C and C++ compilers. Otherwise, once this macro had run, and possibly
put an unguarded statement like this in confdefs.h

  extern "C" void std::exit (int) throw (); using std::exit;

any subsequent C compiler test would get a syntax error.
Here's a comment from c.m4:

  # Some people use a C++ compiler to compile C.  Since we use `exit',
  # in C++ we need to declare it.  In case someone uses the same compiler
  # for both compiling C and C++ we need to have the C++ compiler decide
  # the declaration of exit, since it's the most demanding environment.

If autoconf currently supports such usage, I think it'd be better
to continue supporting 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.

Sounds reasonable.

> 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?
> -  _AC_COMPILE_IFELSE([AC_LANG_PROGRAM(address@hidden:@include <stdlib.h>
> -$ac_declaration],
> address@hidden:@include <stdlib.h>],

It looks like that should be $ac_declaration, not @ac_declaration:


>       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++.

For C aren't we already covered by the inclusion of <stdlib.h>?
I think the goal of that macro is to determine what declaration,
if any, is needed by a C++ compiler, in addition to those in <stdlib.h>,
when compiling a program that calls `exit'.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]