Hi, mspgcc-users@lists.sourceforge.net schrieb am 30.03.04 16:13:52: > > 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. ;-)
that's wrong, because the value of NULL is implementation defined and on some machines the value of NULL is not 0 (see C-FAQs). If you have code which needs NULL to be (arithmetic) 0 you have a code which is not portable and you are casting to/from pointer type from/to artithmetic type. And on the target platform the value of NULL is irrelevant; the program has only to behave standard conform. > - It is gives problems if you use the NULL as FALSE. You are mixing bool types and pointer types. It's like adding apples and bananas. > - It produces more code. No. Why should there be more or less code? > - It is not C Look into the C standard (www.ansi.org) and C-FAQs. Rolf > > 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