casts and puns (and digressions...)

Geoff Kuenning geoff at desint.UUCP
Mon Nov 12 19:37:06 AEST 1984


In article <940 at opus.UUCP> rcd at opus.UUCP (Dick Dunn) writes:

>However, (long*)i is a pun; you just have to stretch
>too far to make any sensible semantics which makes it a true cast.

Oh yeah?  How about non-byte-addressable machines?  A C compiler for the DG
Nova, for example, would have to generate a shift-right instruction for that
cast.  Sounds like a conversion to me.  The same goes for (long) i on most
machines;  you have to sign-extend it.

If I may leap to an unjustified generalization on insufficient data, I wonder
if there is such a thing as a type pun at all, at least in a machine-
independent sense.  On a Vax, for example, (int) i is a pun if i is a long,
but on a PDP-11 it is a truncating conversion (cast).  On most machines a
struct foo * is the same as a struct bar *, but the language doesn't require
it (though if they are different sizes I don't envy the compiler writer).
One can conceive of a machine where every structure had to be aligned on a
structure-size boundary;  it is then reasonable to shift pointers right an
appropriate number of bits.  (This makes the ++ operator easy to implement,
and can be pretty cheap if the machine has built-in left-shifting as part of
the indexing process, similar to the Vax's limited indexing capability.)
-- 

	Geoff Kuenning
	First Systems Corporation
	...!ihnp4!trwrb!desint!geoff



More information about the Comp.lang.c mailing list