Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: Pointers and addresses Message-ID: <4152@goanna.cs.rmit.oz.au> Date: 30 Oct 90 06:29:19 GMT References: <15831@mentor.cc.purdue.edu> <4139@goanna.cs.rmit.oz.au> <15847@mentor.cc.purdue.edu> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 42 In article <15847@mentor.cc.purdue.edu>, shepherd@mentor.cc.purdue.edu (Mike Shepherd) writes: > In article <4139@goanna.cs.rmit.oz.au> ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes: > >In article <15831@mentor.cc.purdue.edu>, > > shepherd@mentor.cc.purdue.edu (Mike Shepherd) writes: > >> Is there a way to change an integer into an address location, vice versa, an > >> address location into an integer? >ok> What on earth is an address location? Do you mean a pointer? >ok> How about an example of what you want to do? > Well, someone apparently did know what I was talking about because > someone DID give me help from the Net. And it worked out very well... " This is just the compiler's way of saying "You know that it's just 32 bits," " and I know that it's just 32 bits, but I'm clever enough to know that it's" " a *different type* of 32 bits." " The thing to do is to use a "cast": .." I have to repeat the negative advice I gave in 4139@goanna. This bit about "you know it's 32 bits and I know it's 32 bits" is a disaster waiting to happen. I gave examples of machines where pointers aren't 32 bits or integers aren't 32 bits. It isn't even the case that all pointers are the same size; there are machines where "data" pointers are 1 word and "function" pointers are 2 (or even more). Even on machines where pointers and ints _are_ the same size, casting may require runtime operations, and casting some bit patterns from int to pointer may cause a trap. The advice you were given is ok _if_ you are _consciously_ writing non-portable code, or at any rate code portable only within a known range of machines ("32-bit byte-addressed workstations running UNIX", say). But that's why it was necessary to ask what you _really_ want to do. Go ahead and make the assumption, but *write it down*, and be prepared to have someone try to port your code to a PC and come screaming for blood. I repeat: how about an example of what you really want to do? Sure, casts are the *obvious* way of hacking it, they're in every elementary introduction to C. But for your actual application, there may be a more portable alternative. -- The problem about real life is that moving one's knight to QB3 may always be replied to with a lob across the net. --Alasdair Macintyre.