Re:
> >Or, perhaps more correctly,
> >
> > byteptr = (char *) inptr;
> >
> >I've seen some C's where the non-casted version will
> >foul up (because the byte addresses differ from non-byte
> >addresses).
>
> I'd get your money back on the C compiler that did that - there's no
> difference between byte and non-byte addresses in C. I've only come across
NO, NO, NO!
You're exhibiting a "vaxocentrism" :)
(Item #3, at http://dictionary.lockergnome.com/find/word/vaxocentrism/ )
> It does get rid of the warnings though so I do use casting anyway.
The warnings are there for a reason!
Some platforms ... generally older mainframe architectures ...
have DIFFERENT forms of addresses for byte addresses vs. non-byte addresses,
and the cast is absolutely, totally, and reallllly needed!
From the "C FAQ"... (comp.lang.c)
("-->" is my addition)
5.17: Seriously, have any actual machines really used nonzero null
pointers, or different representations for pointers to different
types?
A: The Prime 50 series used segment 07777, offset 0 for the null
pointer, at least for PL/I. Later models used segment 0, offset
0 for null pointers in C, necessitating new instructions such as
TCNP (Test C Null Pointer), evidently as a sop to all the extant
poorly-written C code which made incorrect assumptions. Older,
--> word-addressed Prime machines were also notorious for requiring
larger byte pointers (char *'s) than word pointers (int *'s).
The Eclipse MV series from Data General has three
--> architecturally supported pointer formats (word, byte, and bit
pointers), two of which are used by C compilers: byte pointers
for char * and void *, and word pointers for everything else.
Some Honeywell-Bull mainframes use the bit pattern 06000 for
(internal) null pointers.
The CDC Cyber 180 Series has 48-bit pointers consisting of a
ring, segment, and offset. Most users (in ring 11) have null
pointers of 0xB00000000000. It was common on old CDC ones-
complement machines to use an all-one-bits word as a special
flag for all kinds of data, including invalid addresses.
--> The old HP 3000 series uses a different addressing scheme for
byte addresses than for word addresses; like several of the
machines above it therefore uses different representations for
char * and void * pointers than for other pointers.
The Symbolics Lisp Machine, a tagged architecture, does not even
have conventional numeric pointers; it uses the pair <NIL, 0>
(basically a nonexistent <object, offset> handle) as a C null
pointer.
Depending on the "memory model" in use, 8086-family processors
(PC compatibles) may use 16-bit data pointers and 32-bit
function pointers, or vice versa.
--> Some 64-bit Cray machines represent int * in the lower 48 bits
of a word; char * additionally uses the upper 16 bits to
indicate a byte address within a word.
--> References: K&R1 Sec. A14.4 p. 211.
Another possible reference, based on a hint from Google, is the paper
"On defusing a small landmine in the type casting of pointers in the "C" language"
at http://portal.acm.org/ft_gateway.cfm?id=163121&type=pdf
... but you have to be an ACM member to view it, and it looks like that
costs $200/year :(
'nuff said? :)
--
Stan Sieler [log in to unmask]
www.allegro.com/sieler/wanted/index.html www.sieler.com
* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *
|