lint, pointers, 0 (what else?)

jack at boring.UUCP jack at boring.UUCP
Thu Feb 21 02:35:10 AEST 1985


In article <2023 at drutx.UUCP> qwerty at drutx.UUCP (Brian Jones) writes:
>I couldn't help but throw in my $.25 worth - K&R, 14.4:
>
>"A pointer may be converted to any of the integral types LARGE ENOUGH TO HOLD
>IT.  Whether an int or a long is required is MACHINE DEPENDENT." (Emphasis is
>mine)
>
>...
>I have begun to wish for data types such as int8, int16, int32, etc. so that
>programmers could say what they really mean, instead of leaving it as an
>"exercise for the student".
no, No, NO, NO!!!!!
If you use things like 'int16' to store, for instance, the difference
between two pointers, you are just replacing one machine dependency
with another.
Because pointers can only be 2**16 apart on *your* machine does not mean
that this is true for all machines!
What you should have is a 'pointer_diff' type, in which you can store
the difference (signed, probably) between two pointers.

Don't get me wrong, I like the 'int8' idea, but only for storing *normal*
integers, of which the programmer nows that they will allways fit in
8 bits, *not* for storing pointer differences.

(Note that I say 'pointer difference' everywhere. I think this is the only 
legitimate reason for pointer->int conversion. People who store pointers in ints
should be unlink()ed at first sight)
-- 
	Jack Jansen, {decvax|philabs|seismo}!mcvax!jack
Notice new, improved, faster address         ^^^^^



More information about the Comp.lang.c mailing list