Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!shadooby!accuvax.nwu.edu!tank!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: When is a cast not a cast? Message-ID: <17633@mimsy.UUCP> Date: 20 May 89 05:15:27 GMT References: <406@skye.ed.ac.uk> <10276@smoke.BRL.MIL> <2890@buengc.BU.EDU> <1513@hudson.acc.virginia.edu> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 29 -In article <334.nlhp3@oracle.nl> bengsig@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@hudson.acc.virginia.edu> gsh7w@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@mimsy.umd.edu Path: uunet!mimsy!chris