c programming style - READ THIS

Guy Harris guy at sun.uucp
Mon Jul 22 07:35:24 AEST 1985


> In an otherwise OK article, Guy Harris says:
> 
> >        1) The only operation in C that adds an integer to the integer
> >           with the same bit pattern as a given pointer and produces a
> >           pointer value with the same bit pattern as the result is
> >
> >           (pointer_type) ((int)pointer + integer_value)
> >
> >        Guy Harris
> 
> This turns out not to be the case.  The expression "(int)p" where p is a
> pointer does not in any way, shape, or form guarantee to yeild an
> integer with the "same bits" as the pointer p.

Yes, I knew that (having worked for N years on a machine where "int" was 16
bits and pointers were 32 bits), but adding in code to make it work
correctly and explain it to people who don't understand that adding an
integer to a pointer makes the pointer advance by that integer number of the
storage objects pointed to by the pointer, not that integer number of
machine storage units, would probably have totally confused them.

	Guy Harris



More information about the Comp.lang.c mailing list