Mail Archives: djgpp-workers/2000/07/21/14:34:13
DJ Delorie <dj AT delorie DOT com> writes:
> > I don't know what your copy of stdio.h looks like, however, it
> > should certainly test whether NULL is defined before defining it.
>
> It doesn't. It shouldn't have to. ANSI says that stdio.h provides
> NULL. I have a philosophical problem with anyone saying "it should
> certainly test it" because it means that, at the whim of the gcc team,
> we'd need to add yet another test to our standard headers because yet
> another symbol was absconded by the gcc headers. Where does it end?
> Do we have to wrap every single #define in all the system headers?
> Will we have to wrap the function prototypes also?
Note that:
- size_t is defined by stdio.h and stddef.h and string.h and wchar.h;
- NULL is defined by stdio.h and stddef.h and string.h and time.h and wchar.h;
- wchar_t is defined by stdlib.h and stddef.h and wchar.h;
so you already have to test if NULL is defined before defining it.
Actually, the best way to do this is to put this in, say, string.h:
/* Get size_t and NULL from <stddef.h>. */
#define __need_size_t
#define __need_NULL
#include <stddef.h>
and then you don't have to care what the compiler does, your library
will work. A similar technique can be used in stdio.h to implement
vfprintf without defining va_arg.
--
- Geoffrey Keating <geoffk AT cygnus DOT com>
- Raw text -