Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!uxc!uxc.cso.uiuc.edu!ux1.cso.uiuc.edu!uxe.cso.uiuc.edu!mcdonald From: mcdonald@uxe.cso.uiuc.edu Newsgroups: comp.lang.c Subject: Re: When is a cast not a cast? Message-ID: <225800169@uxe.cso.uiuc.edu> Date: 23 May 89 13:17:00 GMT References: <2747@buengc.BU.EDU> Lines: 47 Nf-ID: #R:buengc.BU.EDU:2747:uxe.cso.uiuc.edu:225800169:000:2206 Nf-From: uxe.cso.uiuc.edu!mcdonald May 23 08:17:00 1989 /* Written 1:51 pm May 21, 1989 by peter@ficc.uu.net in uxe.cso.uiuc.edu:comp.lang.c */ In article <2918@buengc.BU.EDU>, bph@buengc.BU.EDU (Blair P. Houghton) writes: > POINTERS ARE NOT MEMORY LOCATIONS. THAT'S A CHILDHOOD > EXAMPLE FOR THE PASCAL-DEPROGRAMMED. GROW UP, C-LAND I'm glad you noticed that. You're the only one who seems determined to think they are. If pointers were simply memory locations, pointer addition would be a non- problem. But they aren't, and it isn't. What do you get when you add segment "xylophone-buggywhip" offset "3 marshmallows" to segment "xylophone- buggywhip" offset "7 marshmallows"? -- Peter da Silva, Xenix Support, Ferranti International Controls Corporation. Business: uunet.uu.net!ficc!peter, peter@ficc.uu.net, +1 713 274 5180. Personal: ...!texbell!sugar!peter, peter@sugar.hackercorp.com. /* End of text from uxe.cso.uiuc.edu:comp.lang.c */ I believe that pointers in C can be cast to some suitable integral type, for example unsigned long. Then you can do what you wish with their value. Then cast back to the pointer of your choice, and if you are suitably knowledgeable about the target machine, the effect of your choice should be achieved. I simply don't understand all the flamage. There seems to be a legal way to do what some people want to do. If it works, it works, if it doesn't work, study some more. (For example, on the machine I am typing this on, an IBM PS/2 Model 80, using my usual C compiler (Microway NDPC), pointers are simply 32bit offsets from some system-supplied origin. It is not hard to figure out what will happen if you cast a few to unsigned int, add and subtract, and cast back. I can easily figure out whether such an operation would give a useful result or an illegal memory trap. Such operations are simply target- machine dependent.) Could somebody (by e-mail, not posting) explain why there is so much flamage on this. Can't it simply be dismissed by the one liner "machine and compiler dependent"? I'll agree that there is no need to make POINTER ADDITION be legal C, since casts allow the effect to be achieved. There are certainly flammable subjects involving pointers, but this isn't one. Doug McDonald