Personally I like to #define NULL to be the string "fish". Works most of the time, except when it doesn't.
Perhaps I should have used Unicode? Note: with French C compilers one has, of course, to use "poisson". ----- Original Message ----- From: "Robert Bon" <r...@dare.nl> To: <mspgcc-users@lists.sourceforge.net> Sent: Tuesday, March 30, 2004 3:04 PM Subject: RE: [Mspgcc-users] Why #define NULL 0? > Kernighan and Ritchie assumed that every computer knows the number zero. > This is the only value the C language uses. > > Using NULL with a value of 42, > - is not portable, a 4bit micro controller doesn't known 42. ;-) > - It is gives problems if you use the NULL as FALSE. > - It produces more code. > - It is not C > > But do what you like. > > Robert Bon > > > -----Original Message----- > From: mspgcc-users-ad...@lists.sourceforge.net > [mailto:mspgcc-users-ad...@lists.sourceforge.net] On Behalf Of > nobo...@web.de > Sent: 2004 March 29 20:30 > To: mspgcc-users@lists.sourceforge.net > Subject: RE: [Mspgcc-users] Why #define NULL 0? > > Hi, > > the definition of NULL is not the problem, the problem is why the NULL macro > is expanded to 0 and not to another value. > I would prefer 42 (see the hitchhikers guide through the galaxy) and i think > chinese would prefer 666. > > Rolf F. > > > mspgcc-users@lists.sourceforge.net schrieb am 29.03.04 09:49:56: > > > > Hello, > > > > Here some info > > > > From The book "The C programming language" by Brain W. Kernighan and > Dennis > > M. Ritchie" ISBN 0-13-110370-9 ISBN 0-13-110362-8 > > Page 102 Chapter 5.4 > > > > "Pointers and integers are not interchangeable. Zero is the sole > exception: > > the constant zero may be assigned to a pointer, and a pointer may be > > compared with the constant zero. The symbolic constant NULL is often used > in > > place of the Zero, as a mnemonic to indicate more clearly that this is a > > special value for a pointer. NULL is defined in <stdio.h>. " > > > > Robert > > > > > > -----Original Message----- > > From: mspgcc-users-ad...@lists.sourceforge.net > > [mailto:mspgcc-users-ad...@lists.sourceforge.net] On Behalf Of > > nobo...@web.de > > Sent: 2004 March 28 00:34 > > To: mspgcc-users@lists.sourceforge.net > > Subject: Re: [Mspgcc-users] Why #define NULL 0? > > > > Hi, > > > > > as far as i know the compiler does if(!foo) => if(0==foo) > =>if(NULL==foo) > > at compile time. > > > > i forgot to say that chapter 6.5.3 (C99) says that the unary operator ! > can > > be applied to a pointer type; that's the reason why it works although on > > first look it seems to work only if the NULL macro is expanded to 0. > > > > > > > But generally it's not possible to compare a pointer with an integer, > > because they the have diffent type and often do not have the same size. On > > sparc64 the user-space pointer have 32 bit while the kernel-space pointers > > have 64 bit, so on that platform comparing integers with pointers is a bad > > idea. > > > Therefore gcc generally produces a warning if he finds such ugly code. > > > > > > > > > >> After all, ain't unary logical operations with pointers illegal? > > > > > > A pointer is an object of size sizeof(pointer); there is no reason why > not > > to apply logical operations with that object. > > > > I forgot to say that maybe for some operators (look into the standard) you > > have to use a union to apply them (to the other member of the union): > > > > union foo > > { > > type *p_p; > > char a_c[sizeof(type *)]; > > }; > > I > > If sizeof(int) == sizeof(type *) than you can use int as the second > member. > > I > > Rolf F. > > > > > > > > > > ------------------------------------------------------- > > This SF.Net email is sponsored by: IBM Linux Tutorials > > Free Linux tutorial presented by Daniel Robbins, President and CEO of > > GenToo technologies. Learn everything from fundamentals to system > > administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click > > _______________________________________________ > > Mspgcc-users mailing list > > Mspgcc-users@lists.sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/mspgcc-users > > > > > > > > ------------------------------------------------------- > > This SF.Net email is sponsored by: IBM Linux Tutorials > > Free Linux tutorial presented by Daniel Robbins, President and CEO of > > GenToo technologies. Learn everything from fundamentals to system > > administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click > > _______________________________________________ > > Mspgcc-users mailing list > > Mspgcc-users@lists.sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/mspgcc-users > > > > > > ------------------------------------------------------- > This SF.Net email is sponsored by: IBM Linux Tutorials > Free Linux tutorial presented by Daniel Robbins, President and CEO of > GenToo technologies. Learn everything from fundamentals to system > administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click > _______________________________________________ > Mspgcc-users mailing list > Mspgcc-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/mspgcc-users > > > > ------------------------------------------------------- > This SF.Net email is sponsored by: IBM Linux Tutorials > Free Linux tutorial presented by Daniel Robbins, President and CEO of > GenToo technologies. Learn everything from fundamentals to system > administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click > _______________________________________________ > Mspgcc-users mailing list > Mspgcc-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/mspgcc-users --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.631 / Virus Database: 404 - Release Date: 17/03/04