Pointers are ints, zero is null, and strings are null terminated.

Pointers are ints, zero is null, and strings are null terminated.

Post by Kelsey Bja » Sun, 09 Jan 2005 05:34:27



If pointers are ints, explain to me why I can create full 32-bit-long
pointers on an implementation with 16 bit ints.

And no, that's not some hypothetical issue, I've written a lot of code
over the years for just such a system.
 
 
 

Pointers are ints, zero is null, and strings are null terminated.

Post by The Ghost » Sun, 09 Jan 2005 08:02:05

In comp.os.linux.advocacy, Kelsey Bjarnason
< XXXX@XXXXX.COM >
wrote
on Fri, 07 Jan 2005 20:34:27 GMT
< XXXX@XXXXX.COM >:


MAKELONG(lo, hi) or some such. (And yes, it's an
extremely ugly Windows construct, whatever it is.
It's also a rather old one.)

Of course this illustrates Jeff's relatively narrow view on
the entire "null pointer issue". I can't say I've worked
on any system where NULL != 0, but I also can't say that
it's impossible, and I do know of one system (DOS-based
C) where one has to be careful as *(char *) 0 = 'X' would
actually work, if one can call trashing a value at the zero
offset of the data segment "working".

Also, std::string, which I've mentioned before, doesn't bother
to terminate strings with \0 unless one calls c_str(). It's
also far easier to hold onto std::string than char * pointers
in such things as std::set, std::map, and std::list. (There
are areas I prefer STL to Java; consistent use of begin()/end()
and ::iterator is one of them. Java is better in other areas.
Eenie Meanie... :-) )


And you will again -- only this time the ints are 32 bit, and
the pointers 64. :-)

--
#191, XXXX@XXXXX.COM
It's still legal to go .sigless.