Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!uxc!uxc.cso.uiuc.edu!m.cs.uiuc.edu!s.cs.uiuc.edu!carroll From: carroll@s.cs.uiuc.edu Newsgroups: comp.lang.c Subject: Re: When is a cast not a cast? Message-ID: <207600022@s.cs.uiuc.edu> Date: 19 May 89 14:14:00 GMT References: <2747@buengc.BU.EDU> Lines: 29 Nf-ID: #R:buengc.BU.EDU:2747:s.cs.uiuc.edu:207600022:000:1472 Nf-From: s.cs.uiuc.edu!carroll May 19 09:14:00 1989 /* Written 11:19 am May 18, 1989 by gsh7w@astsun1.acc.Virginia.EDU in s.cs.uiuc.edu:comp.lang.c */ #In article <334.nlhp3@oracle.nl> bengsig@oracle.nl (Bjorn Engsig) writes: ##[ pointer overflow example ] #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. # /* End of text from s.cs.uiuc.edu:comp.lang.c */ Ah, but that's an entirely different case. The programmer has complete control over what's in those int variables, and can do overflow checking before hand, or just use unsigned arithmetic where the result is defined (it is mod 2^(sizeof(int)*bits_per_byte)). The programmer, however, has _no_ control over where the pointers are, or what the actual values in them are. He could prevent the case you talk about for int's, but how would you do it for pointers? You may think "only in contrived examples", but on a 3b2, all user space pointers are such that adding them _will_ cause overflow (static/malloc are 0x8000000, stack 0xC000000). I can write portable code that prevents int overflow. I can't do that for pointers. Alan M. Carroll "And there you are carroll@s.cs.uiuc.edu Saying 'We have the Moon, so now the Stars...'" CS Grad / U of Ill @ Urbana ...{ucbvax,pur-ee,convex}!s.cs.uiuc.edu!carroll