NULL vs 0 - chapter and verse

Henry Spencer henry at utzoo.UUCP
Tue Jan 24 10:36:11 AEST 1984


Charles LaBrec observes:

  Guy however pointed out something about the 32/16 problem that does break
  the standard--the fact that the subtraction of two pointers produces an
  int that is the number of elements between the two pointers.  I don't see
  a "portable" way of resolving this difficulty.

Lots of fun.  In fact, it gets worse.  If you have a 32-bit machine
that uses all 32 bits for pointers, there may be *no* C data type big
enough to hold the difference of two pointers.  The difference should
clearly be signed (positive or negative depending on whether a > b or
a < b), but with 32 bits of pointer an unsigned long is just barely
large enough to hold the magnitude, and there's no room for the sign.

The ANSI-C-standard people are aware of this one (in fact, I first heard
about it from one of them); it's not clear that they can come up with
a clean and simple solution.
-- 
				Henry Spencer @ U of Toronto Zoology
				{allegra,ihnp4,linus,decvax}!utzoo!henry



More information about the Comp.unix.wizards mailing list