The dictionary definition of the word NULL encompasses 0 (Zero). See
http://www.hyperdictionary.com/dictionary/null
Don't just read the first part, read the entire entry.  Anyway, null and zero
are synonymous, therefore many people consider NULL also means 0 (zero). Make up
your own mind, but personally have always considered NULL and ZERO have
essentially the same meaning.

This is the mathematical sense of the word NULL, although maybe not  the legal
sense. Note that the computing dictionary actually says that it is a pointer to
0, which is its current usage under gcc. (How did this get changed to a pointer
type in the first place?)

I much prefer NULL to be typeless, and 0, Not cast to a pointer.
IE: #define NULL 0
That way, you get the most efficient coding, no matter how you use NULL (because
it is a constant) . The compiler then decides what to do in the most efficient
manner. #define NULL (void *) 0  violates the use of NULL as another word for
zero for me.

You can always redefine NULL yourself at the top of your source if you want it
to mean something other than (void *) 0.
(Which, I will do in future, now this has been pointed out!)

Cheers
Harry



-----Original Message-----
From: mspgcc-users-ad...@lists.sourceforge.net
[mailto:mspgcc-users-ad...@lists.sourceforge.net]on Behalf Of Steve Underwood
Sent: Wednesday, March 31, 2004 10:02 AM
To: mspgcc-users@lists.sourceforge.net
Subject: Re: [Mspgcc-users] Why #define NULL 0?

Hi all,

Well, this discussion has been great fun :-\ , but getting back to the
original point......

The original poster said that using zero for NULL raised issues on the
MSP430, as there is actually something at zero (at least, I think that
was their intent). However, nobody has yet identified any real problems
this casues. The thing at zero is a register, which one would not
normally access by pointer. Some other registers, like the port
registers, might be accessed by pointer and offset. It has merit there,
since each port has a similar register group. The register at zero isn't
like that, though, and I can't imagine any cause for using a pointer to it.

Can anyone raise any real issues with NULL being zero? Changing it now
would be a big pain, and would make mspgcc incompatible with a lot of
code produced for other MCU C compilers.

Regards,
Steve

nobo...@web.de wrote:

>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
>
>



-------------------------------------------------------
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


Reply via email to