Message-Id: Comments: Authenticated sender is From: "Salvador Eduardo Tropea (SET)" Organization: INTI To: "Andris Pavenis" , Peter Palotas , djgpp AT delorie DOT com, djgpp-workers AT delorie DOT com Date: Wed, 25 Mar 1998 11:23:45 +0000 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: NULL redefined! :( In-reply-to: <199803251406.QAA57422@ieva06.lanet.lv> References: <3518F995 DOT 6AEA AT rug DOT ac DOT be> Precedence: bulk "Andris Pavenis" wrote: > > Date: Wed, 25 Mar 1998 13:33:25 +0100 > > From: Vik Heyndrickx > > Subject: Re: NULL redefined! :( > > > Salvador Eduardo Tropea (SET) wrote: > > > But perhaps we must investigate if the __null have some advantage and: > > > > > > 1) Define NULL conditionally (no redefinition) > > > 2) If not defined: > > > a) Test the gcc version, if 2.8.0 define with __null > > > b) if prior define with 0. > > > > Conditional redefinition is dangerous since this way NULL might get two > > values that do not compare equal, even when compiled with the same > > compiler version. > > An unconditional #define is best (i.e. preceded with #undef) as it only > > disadvantages programs which are at fault. > > > > Checking whether gcc's version is 2.8.0, won't help a bit: > > for instance the libc library can have been defined using gcc-2.7.2.1 > > and hence NULL would be 0. A program compiled with 2.8.0 would then > > define NULL as __null. Like DJ mentionned, a library function like fopen > > can return NULL (=0) and it must be possible that a program compares it > > with NULL (=__null). > > > > I suggest to copy definition of NULL to .h files that conflicts > with ones from gcc 2.8.0 (%DJDIR%/lang/cxx/libio.h vai > %DJDIR%/lang/cxx/streambuf.h) > > ------------------------------------------------------- > #ifndef NULL > # if defined __GNUG__ && \ > (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)) > # define NULL (__null) > # else > # if !defined(__cplusplus) > # define NULL ((void*)0) > # else > # define NULL (0) > # endif > # endif > #endif > ------------------------------------------------------- > > I did so and don't have any problems yet. I agree and that's just what I propossed at first (conditional definition taking care of the gcc version). The only doubt about this piece of code: I think that it needs an extra test for C++ because __null doesn't exist in C, perhaps: #ifndef NULL // Not NULL defined #ifdef __cplusplus // C++ case # if defined __GNUC__ && \ (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)) # define NULL (__null) # else # define NULL ((void *)0) #else // C case # define NULL (0) #endif #endif SET ------------------------------------ 0 -------------------------------- Visit my home page: http://set-soft.home.ml.org/ or http://www.geocities.com/SiliconValley/Vista/6552/ Salvador Eduardo Tropea (SET). (Electronics Engineer) Alternative e-mail: set-soft AT usa DOT net set AT computer DOT org CQ: 2951574 Address: Curapaligue 2124, Caseros, 3 de Febrero Buenos Aires, (1678), ARGENTINA TE: +(541) 759 0013