Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 beta 3/9/83; site desint.UUCP Path: utzoo!watmath!clyde!bonnie!akgua!sdcsvax!sdcrdcf!trwrb!desint!geoff From: geoff@desint.UUCP (Geoff Kuenning) Newsgroups: net.lang.c Subject: Re: casts and puns (and digressions...) Message-ID: <210@desint.UUCP> Date: Mon, 12-Nov-84 04:37:06 EST Article-I.D.: desint.210 Posted: Mon Nov 12 04:37:06 1984 Date-Received: Wed, 14-Nov-84 04:25:10 EST References: <110@ISM780B.UUCP> <940@opus.UUCP> Organization: his home computer, Thousand Oaks, CA Lines: 26 In article <940@opus.UUCP> rcd@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