When is a cast not a cast?

Chris Torek chris at mimsy.UUCP
Sat May 20 15:15:27 AEST 1989


-In article <334.nlhp3 at oracle.nl> bengsig at oracle.nl (Bjorn Engsig) writes:
->Pointer addition IS meaningless.  Let's take an example of a 3 bit machine
->with only 0, 1, 2, ... , 7 as the only addresses.  Let's also declare
->
->char *p, *q;
->
->and let p==3 and q==5.  Then what is p+q?  Which type does it have?  The
->presumed answer of '8' cannot be stored in this machine.

In article <1513 at hudson.acc.virginia.edu> gsh7w at astsun1.acc.Virginia.EDU
(Greg Hennessy) writes:
-Then why can't one say "Integer addition IS meaningless. Let's take an
-example of a 16 bit machine. Let's also declare
-
-int i,j;
-
-and let i == 32000 and q == 32767. Then what is I+j? Which type does
-it have? The presumed answer of `64767' cannot be stored in this
-machine. 

Indeed, and the result of the addition is therefore undefined.  On
some machines you get an apparently nonsense answer (-769) and on
others you get a runtime error.  The difference between this and
pointer addition is that correct code can guarantee proper integer
values before addition, but cannot guarantee proper pointer values
before addition.  (You may not portably inspect a pointer's value.)
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list