Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!mcvax!ukc!etive!aiai!richard From: richard@aiai.ed.ac.uk (Richard Tobin) Newsgroups: comp.lang.c Subject: Re: When is a cast not a cast? Message-ID: <464@skye.ed.ac.uk> Date: 19 May 89 17:51:26 GMT References: <406@skye.ed.ac.uk> <10276@smoke.BRL.MIL> <2890@buengc.BU.EDU> <334.nlhp3@oracle.nl> Reply-To: richard@aiai.UUCP (Richard Tobin) Organization: AIAI, University of Edinburgh, Scotland Lines: 30 In article <334.nlhp3@oracle.nl> bengsig@oracle.nl (Bjorn Engsig) writes: >>>In article <406@skye.ed.ac.uk> richard@aiai.UUCP (Richard Tobin) writes: >>>> t = p + q; >char *p, *q; > >and let p==3 and q==5. Then what is p+q? Which type does it have? I'm not of course suggesting that this should be added to C. However, I don't think it would be *impossible* to specify semantics for it. p+q would have type "sum of 2 pointers to char". Subtracting a pointer to char would give a pointer to char. Adding a pointer to char would give "sum of 3 pointers to char". Adding a pointer to int would give "sum of 2 pointers to char and a pointer to int". (We of course need some canonicalisation here.) Dereferencing would of course be illegal. It might be an error to mix pointers to different aggregates. Just to reiterate, I don't think this should really be done. I would hope that a compiler would generate good enough code for my original example, but I haven't seen one that does. -- Richard -- Richard Tobin, JANET: R.Tobin@uk.ac.ed AI Applications Institute, ARPA: R.Tobin%uk.ac.ed@nsfnet-relay.ac.uk Edinburgh University. UUCP: ...!ukc!ed.ac.uk!R.Tobin