Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!sun-barr!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: <406@skye.ed.ac.uk> Date: 3 May 89 11:57:45 GMT References: <2747@buengc.BU.EDU> <10191@smoke.BRL.MIL> Reply-To: richard@aiai.UUCP (Richard Tobin) Organization: AIAI, University of Edinburgh, Scotland Lines: 44 >Addition of pointers is a meaningless operation. Not always. (I'm not discussing whether it's legal in C, just whether it's meaningless.) This is perfectly reasonable: char *p, *q, *r, *s; ... for(...) { ... s = p + (q - r); ... } (assuming they point into the same array). Now suppose p and q are constant in the loop, but r isn't. Then you might want to do: t = p + q; for(...) { ... s = t - r; ... } Of course, there's no reasonable declaration for t, so you'd probably have to use some casts and treat them as integers (no flames please; for some people writing some programs sometimes portability to some machines isn't important). A good compiler might do this for you. -- Richard -- Richard Tobin, JANET: R.Tobin@uk.ac.ed AI Applications Institute, ARPA: R.Tobin%uk.ac.ed@nss.cs.ucl.ac.uk Edinburgh University. UUCP: ...!ukc!ed.ac.uk!R.Tobin