This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: GCC headers and DJGPP port


DJ Delorie <dj@delorie.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@cygnus.com>

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]