sizes of pointers
Norman Diamond
ndiamond at watdaisy.UUCP
Fri Feb 8 04:42:27 AEST 1985
Two independent ideas here:
(1) There still exists a wide variety of machines, including new ones
invented almost daily, where registers are not large enough to hold
pointers and address arithmetic is non-trivial and you would not want
to make sizeof (anytype *) == sizeof (int). You still COULD increase
the size of an int so that sizeof (sometypes *) == sizeof (int), but
you would regret the waste of space and/or subroutine calls to do all
of your int arithmetic.
(2) If you want to define some null pointer that's pretty well guaranteed
to work, and pass it as a parameter to a subroutine, you can make your
null pointer (char *) 0, and make all of your pointer parameters char *'s.
Why? Because: calloc returns a char *, and you can always cast the result
to convert to any kind of <type> * that you might need. Therefore we know
sizeof (char *) >= sizeof (anytype *), for any anytype. Of course, your
procedure calls will have to cast all pointer parameters to char *'s, and
your procedure code will have to cast them back.
--
Norman Diamond
UUCP: {decvax|utzoo|ihnp4|allegra|clyde}!watmath!watdaisy!ndiamond
CSNET: ndiamond%watdaisy at waterloo.csnet
ARPA: ndiamond%watdaisy%waterloo.csnet at csnet-relay.arpa
"Opinions are those of the keyboard, and do not reflect on me or higher-ups."
More information about the Comp.lang.c
mailing list