Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site watmath.UUCP Path: utzoo!watmath!kpmartin From: kpmartin@watmath.UUCP (Kevin Martin) Newsgroups: net.lang.c Subject: Re: casts and puns (and digressions...) Message-ID: <9890@watmath.UUCP> Date: Sat, 17-Nov-84 15:33:37 EST Article-I.D.: watmath.9890 Posted: Sat Nov 17 15:33:37 1984 Date-Received: Sun, 18-Nov-84 03:41:25 EST References: <110@ISM780B.UUCP> <940@opus.UUCP> <210@desint.UUCP> Reply-To: kpmartin@watmath.UUCP (Kevin Martin) Organization: U of Waterloo, Ontario Lines: 30 In article <210@desint.UUCP> geoff@desint.UUCP (Geoff Kuenning) writes: >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. (Throw glass of cold water in person's face, grab then by the shoulders and shake them, slap them in the face a few times, look them squarely in the face, and, for the n+1st time, say...) THERE IS NO RULE THAT SAYS THAT (long *)i MUST POINT TO THE i'TH long OR TO THE i'TH BYTE OR TO THE i'TH ANYTHING. It just happens to do this on pdp11's, vaxes, 68000's, 8086's, etc. On a NOVA, (int *)1 could just as well point at word 1, and (char *)1 as the lower byte of word 1, and (char *)0100001 at the upper byte of word 1, etc. In which case the cast really is a pun. If a C compiler for the NOVA does a shift for int->pointer conversions, it is only through the kindness of heart (and/or lack of brains) on the part of the compiler developers. It is tough enough making sure zero turns into the machine's null pointer without having to make every integer point to the corresponding byte too. Kevin Martin, UofW Software Development Group.