[comp.lang.c] handles, pointers, etc

dave@sds.UUCP (dave schmidt x194) (05/26/87)

>> To the "outside world", each object is known only by a handle, which is
>> typically (here it comes, folks) a pointer to that malloc'ed struct.
>> [...] 
>> Possibility #1:  We cavalierly declare that no pointers are longer than
>> char pointers:

>Does the word "assume" ring a bell?

From K&R, p. 210:
"A pointer to one type may be converted to a pointer to another type. [...]
It is guaranteed that a pointer to an object of a given size may be converted
to a pointer to an object of a smaller size and back again without change."

This means that all that is really assumed by "Possibility #1" is that
a character is the smallest data object which can be pointed at (e.g., bit
fields don't count).  In fact, unless you have something quasi-strange
like sizeof(char) == sizeof(short) or sizeof(char) == sizeof(int), this
passage of K&R effectively guarantees that a character pointer is the
"longest" data pointer possible.  If you have something like 
sizeof(char) == sizeof(short), then all bets are off because K&R doesn't
say "object of a smaller *or equal* size" and so a (short *) could be
longer than a (char *) in this instance.

In sum, there is an assumption being made by "Possibility #1", but it's
a pretty safe one.