casts and puns (and digressions...)

Geoff Kuenning geoff at desint.UUCP
Tue Nov 20 11:37:20 AEST 1984


In article <9890 at watmath.UUCP> kpmartin at watmath.UUCP (Kevin Martin) writes:

>In article <210 at desint.UUCP> geoff at desint.UUCP (Geoff Kuenning) writes:
>>
>>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...)
>
>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.

Before you go around slapping people and throwing cold water in their face,
Kevin, you should be sure what you are doing.  Otherwise you are going to
offend people.  In this case, you have exhibited a fair amount of ignorance
regarding the Nova, ignored statements in the latter part of the article,
and accused a number of compiler writers who you have never met of a lack
of brains.  For your information, there are two ways one can do byte
pointers on the Nova.  One is to store an index of the i'th byte from
location zero.  The other is to use bit 15 as the byte pointer.  But, with
the Nova instruction set, testing bit 15 requires a shift.  And bit 15 must
be cleared before you access the word you want, because it is an indirect
bit.  If you store a "byte pointer", you can do the test, adjustment, and
clearing of bit 15 in a single instruction.  If you store the odd-byte bit
in the high bit, not only is your heavily-used byte-get routine significantly
slower, but you also have a really nasty problem with incrementing the things.

Obviously, word pointers should be stored as word pointers for efficiency
reasons.  Thus, you have a machine where the optimal pointer representation
differs depending on the type.

'Nuff said?
-- 

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



More information about the Comp.lang.c mailing list