GCC's <assert.h> and C99

Zack Weinberg zack@rabi.columbia.edu
Sat Sep 23 15:08:00 GMT 2000


On Sat, 23 Sep 2000 16:06:45 +0900 (JST), Martin Buchholz wrote:
>>>>>> "ZW" == Zack Weinberg <zack@rabi.columbia.edu> writes:
>
>ZW> You were told, months ago, that the proper way to fix the __eprintf proble
>m
>ZW> - yes, we accept that it is a problem - is to submit a two line patch for
>ZW> the target Makefile fragment for the systems you care about (e.g. t-svr4):
>
>ZW> +# Use the system <assert.h>.
>ZW> +INSTALL_ASSERT_H =
>
>I don't believe in adding more stuff to system-specific files.  Of
>course, gcc is bound to be non-portable, but still one should try hard
>to autoconfiscate everything.

Yes, autoconfiscating everything is desirable, but at the moment the above
is the only option we have.  It works, it's the documented solution to your
problem, it's two lines of code.

>ZW> Alternatively, you could write a clever autoconf test which determines if
>ZW> the target has a C89 compliant <assert.h> and disables installation of our
>ZW> header if it does.  That would fix the problem for everyone, but would be
>ZW> substantially harder.
>
>Hmmmmm.

I'll get you started - there's a suitable test program at the end of the
message.

The tricky bit will be compiling and linking it with the target headers. 
You'll have to postpone the test until after the compiler has been built,
and disable it if inhibit_libc is defined (in that case, assume the libc to
be built will provide a good copy of the header).

>ZW> Why have you not done either of these things?
>
>Maybe because I'm busy maintaining my own amazingly buggy free
>software.  

It'd take you less brain time to generate and test the above two line patch
than it would to complain about the current situation so loudly.

>Offhand, it looks hard for a libc implementor to provide an assert.h
>that works for both c89 and c9x without compiler-specific hacks.  How
>do you test for support for __func__?

#if defined __STDC_VERSION__ && __STDC_VERSION__ > 199901L
/* we have __func__ */
#endif

zw

-- test-assert.c --
/* Test as much of assert() as can be tested without running a program.
   This program should link if compiled with -DNDEBUG, and fail to link
   without, but should get no compiler failures in either case.  */

extern int predicate (void);

#include <assert.h>

int main(void)
{
  assert (predicate ());
  return 0;
}


More information about the Gcc mailing list