NULL is a pointer and therefor 32 bit long, 0 is an integer and in the prc-tools, integers are only 16 bit long. So you should see a difference between (NULL + 0x10) * 0x1000 and (0 + 0x10) * 0x1000. The first should (as far as I know) be calculated in 32 bit, the other in 16 bit. The first will get the correct result of 0x10000, the second will overflow, IMHO.

Logan Shaw wrote:

Andrew J. Huang wrote:

This is a really pretty dumb question, but NULL and 0 act
differently using the gnu toolchain.  What exactly is the
difference?


Not necessarily a dumb question; it is one of the finer points of C,
since initially you just see lots of references to NULL and only
later start to consider what the relationship between 0 and NULL is
exactly.

Anyway, if you have a copy of the K&R book, look at section 5.4
(p. 102 in my copy).  There you will find the following:

        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 of zero, as a mnemonic
        to indicate more clearly that this is a special value for a
        pointer.  NULL is defined in <stdio.h>.

So, the answer is that NULL and zero should be the same in C.
I believe the same applies to C++.

So, if the GNU toolchain is treating them differently, that would
appear to be a problem with the toolchain.  However, I can imagine
that NULL could be #define'd as either "((void *) 0)" or just "(0)",
and I suppose the two might actually act slightly differently in
some cases[1].

For more information, you could consult the newsgroup comp.lang.c,
where you will find people who have seemingly devoted their lives
to knowing the correct answers to pedantic questions about C.  :-)

By the way, have you tried searching the header files for "NULL"
to see how your system defines it?  On Unix(-ish) systems, you
could probably find the answer with something like
"grep -w 'define.*NULL' *.h" or the equivalent
recursive-directory-searching incantation.

  - Logan

[1]  And there is always the possibility that rather than
     "#define NULL (0)" they might have used something like
     "static const void *NULL = 0;".



--
-------------------------------------------------------------------------
  Henk Jonas
  Palm OS � certified developer

  [EMAIL PROTECTED]                                   www.metaviewsoft.de
-------------------------------------------------------------------------

--
For information on using the Palm Developer Forums, or to unsubscribe, please 
see http://www.palmos.com/dev/support/forums/

Reply via email to