%p and different pointer representations

Chris Torek chris at mimsy.UUCP
Sun Feb 26 19:36:24 AEST 1989


In article <592 at jhereg.Jhereg.MN.ORG> mark at jhereg.Jhereg.MN.ORG
(Mark H. Colburn) writes:
>Wait a minute, Chris.  The pANS says (ss 3.2.2.3, pp 37 Oct 31, 88):
>
>"A pointer to void may be converted to or from a pointer to any 
> incomplete or other type.  A pointer to any incomplete or object 
> type may be converted to a pointer to void and back again; the 
> result shall compare equal to the original pointer."

I believe this paragraph refers only to `data' pointers---at least, the
last time I checked carefully, `void *'s were not supposed to be used
to hold function pointers.  Function pointers are sometimes bigger than
data pointers, as with medium model IBM PC compilers and (to a greater
extent) with Sperry systems (I hear one compiler for the Univac 1100
has 18-bit pointers to data objects and 162-bit pointers to functions).
Again, the last time I checked---I do not now have access to the current
proposed standard---the standard had essentially two major sub-groups
of pointers, and said that, for all data types T1, T2:

	if sizeof(T1) < sizeof(T2), sizeof(T1 *) >= sizeof(T2 *)

	sizeof(T1 *) <= sizeof(char *) == sizeof(void *)

	sizeof(T1 (*)()) == sizeof(T2 (*)())

In English: a pointer to one data type can only have more bits than a
pointer to another if the first type (T1) has more bits than the
second; all data pointers (but not necessarily function pointers)
fit in (char *)/(void *); and all function pointers fit in each other.

>What you are saying would seem to contradict this.

I do remember that, at one point, I thought (void *) had to hold
function pointers as well.  Knowing of medium model and of that Sperry
compiler, I checked the then-current draft, and (after much squinting
and re-reading of fine print) discovering otherwise.

>Also, I don't beleive that there is any requirement that (void *) has to be
>2 bytes long.  In my opinion void should be defined to be at least as
>large as the largest pointer available in the current compiler model.

I would agree.  Alas, the standard says that (void *) and (char *) must
have the same representation, so to comply with our opinions (as
opposed to the letter of the proposed standard), an IBM PC compiler or
Sperry compiler or . . . would have to make (char *) be twice, or nine
times, or whatever, as big as necessary.  (If the proposed standard
says only that (void *) must hold function pointers, one could avoid
this penalty for (char *) pointers.)
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list