Mail Archives: djgpp-workers/2000/03/08/11:40:09
[...]
> > > > > > #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 -