datangua@watmath.waterloo.edu (David Tanguay) (02/05/91)
In article <15067@smoke.brl.mil> gwyn@smoke.brl.mil (Doug Gwyn) writes: >Also, each implementation is required to >provide SOME integral type to which any data pointer can be cast such >that upon subsequent cast back to the same type of pointer, the new >pointer value will compare equal to the old value. Where does the standard say this? 3.3.4 says a pointer may be converted to some integral type, and that an integer may be converted to a pointer, but the result is implementation defined. Whether or not the pointer value is preserved across pointer -> int -> pointer is implementation defined. For example, the pointer -> integer conversion could drop the segment of the pointer, and the integer -> pointer could apply some default segment (the integer gets the offset). -- David Tanguay Software Development Group, University of Waterloo
henry@zoo.toronto.edu (Henry Spencer) (02/06/91)
In article <1991Feb4.234142.26867@watmath.waterloo.edu> datangua@watmath.waterloo.edu (David Tanguay) writes: >>Also, each implementation is required to >>provide SOME integral type to which any data pointer can be cast such >>that upon subsequent cast back to the same type of pointer, the new >>pointer value will compare equal to the old value. > >Where does the standard say this? ... Doug is probably thinking of the language in older drafts, which did promise that there was such an integer type. The final standard does not. Be nice, though: he's not the only one to have overlooked this. -- "Maybe we should tell the truth?" | Henry Spencer at U of Toronto Zoology "Surely we aren't that desperate yet." | henry@zoo.toronto.edu utzoo!henry
gwyn@smoke.brl.mil (Doug Gwyn) (02/06/91)
In article <1991Feb4.234142.26867@watmath.waterloo.edu> datangua@watmath.waterloo.edu (David Tanguay) writes: >In article <15067@smoke.brl.mil> gwyn@smoke.brl.mil (Doug Gwyn) writes: >>Also, each implementation is required to >>provide SOME integral type to which any data pointer can be cast such >>that upon subsequent cast back to the same type of pointer, the new >>pointer value will compare equal to the old value. >Where does the standard say this? 3.3.4 says a pointer may be converted >to some integral type, and that an integer may be converted to a pointer, >but the result is implementation defined. Oops, you're right. The base document made the guarantee, but somewhere along the way X3J11 decided that it was impractical to guarantee that the same representation would be obtained upon reconversion to a pointer, and that they did not want to require implementation of the "equivalence class" notion for pointer equality that I mentioned previously. There is an even more insidious problem lurking in the way the standard ended up, which is that an ARBITRARY integral value must be convertible to any pointer type, whether or not alignment and address bound requirements are met. This could cause implementations to have to perform some extra work when an integer is converted to some pointer types. Sorry for relying on my fuzzy memory instead of on the standard..