delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2000/03/08/11:40:09

X-Authentication-Warning: acp3bf.physik.rwth-aachen.de: broeker owned process doing -bs
Date: Wed, 8 Mar 2000 14:51:20 +0100 (MET)
From: Hans-Bernhard Broeker <broeker AT physik DOT rwth-aachen DOT de>
X-Sender: broeker AT acp3bf
To: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
cc: djgpp-workers AT delorie DOT com
Subject: Re: iso646.h and some questions
In-Reply-To: <Pine.SUN.3.91.1000308151848.8110A-100000@is>
Message-ID: <Pine.LNX.4.10.10003081434500.16372-100000@acp3bf>
MIME-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com
Errors-To: dj-admin AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

[...]
> > > > > > 	#undef NULL
> > > > > > 	#define NULL 0

> Wrong command.  It misses these two lines from stdlib.h:
> 
>   /* Some programs think they know better... */
>   #undef NULL

I knew we always #undef it before #define NULL 0, as you can see in the
quoted fragment above. But on closer inspection, I think that doesn't
really solve the problem either.

[...]
> reason turned to be that the C++ compiler has its own definition
> of NULL, pulled from some C++ header.

That figures. But it also means that depending on the order of C and C++
header #include's, C++ will still break, I think. I haven't tested it,
here (no DJGPP at hand), but if the last #include in a C++ program is,
say, <stdio.h>, C++ will barf because NULL is now defined as 0, instead of
the __null it wants.

So the current method is still not a full solution, either. Let me propose
an alternative that should always work. Introduce a new file, to keep it
tightly organized. Lets call it <sys/djnull.h>:

--- new file --- 
/* Decorate with #ifndef multi-inclusion catcher, and 'extern "C"', as
 * pleases... */
#ifdef __cplusplus
# define _DJ_NULL __null /* C++ wants this, for 'NULL' */
#else
# define _DJ_NULL 0      /* C needs this, instead */
#endif
--- end file ---

Then, all the

	#undef NULL
	#define NULL 0

sequences in the C standard headers could be replaced by

	#include <sys/djnull.h>
	#ifndef NULL
	#define NULL _DJ_NULL
	#endif

This should work for both C and C++ compiles. Or doesn't the C++ __null
evaluate to a C-usable NULL pointer constant, if passed to an extern "C"
function?

Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019