tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: NULL pointer arithmetic issues



On 2020-02-24 21:18, Mouse wrote:
If we use 0x0, it can be a valid pointer.

If we use NULL, it's not expected to work and will eventually
generate a syntax erro.

Then someone has severely broken compatability with older versions of
C.  0x0 and (when one of the suitable #includes has been done) NULL
have both historically been perfectly good null pointer constants.

Also...syntax error?  Really?  _Syntax_ error??  I'd really like to see
what they've done to the grammar to lead to that; I'm having trouble
imagining how that would be done.

Unless I remember wrong, older C standards explicitly say that the integer 0 can be converted to a pointer, and that will be the NULL pointer, and a NULL pointer cast as an integer shall give the value 0.

This is also used in such things as code traversing linked lists to check for the end of the list...

And the C standard also explicitly allows the NULL pointer to not be represented by something with all bits cleared. Only that casting to/from integers have a very defined behavior.

  Johnny

--
Johnny Billquist                  || "I'm on a bus
                                  ||  on a psychedelic trip
email: bqt%softjar.se@localhost             ||  Reading murder books
pdp is alive!                     ||  tryin' to stay hip" - B. Idol


Home | Main Index | Thread Index | Old Index