Newsgroups: comp.sys.mac.programmer Path: utzoo!censor!geac!alias!fred!rae From: Reid Ellis Subject: Is Technote #213 wrong? Message-ID: Summary: Technote 213 implies that subtracting two pointers can give garbage values. Keywords: stripaddress, 24-bit, 32-bit Sender: Reid Ellis Reply-To: Reid Ellis Organization: Alias Research, Inc. Toronto ON Canada Date: 24 Oct 90 17:50:07 GMT This regards Technote #213, whose header is as follows: #213: _StripAddress: The Untold Story Revised by: Paul Snively & Andrew Shebanow August 1990 Written by: Andrew Shebanow October 1988 Inside Macintosh, Volume V, The OS Utilities, incorrectly documents the _StripAddress trap; this Technical Note correctly documents the trap and gives guidelines for its use. Changes since April 1990: Added a discussion of why the _StripAddress trap should be used under certain circumstances when patching traps. In the body of the technote, it is stated: You do not need to call _StripAddress before performing address arithmetic, since adding or subtracting two 24-bit addresses always results in the correct 24-bit address, regardless of the high byte values. This first sentence confuses me. The paragraph then goes on to say: ... Random high byte values can cause ordered comparisons on the results of pointer arithmetic to fail, since underflow or overflow could occur, so you should never test the result of address arithmetic against a value (only against NIL or 0). The result of subtracting two addresses is an integer, not an address. Addition of two addresses has no meaning whatsoever. What goes on? If I have two addresses [say indices into an array] named ptr1 and ptr2, can I meaninfully say the following? if(ptr2 - ptr1 < sizeof(array)) { ... } This is of great concern to me. I had always assumed code like this would work as well on the Macintosh as it does elsewhere. My guess is that the person who wrote the above paragraph was told that pointer arithmetic would work, but wasn't told clearly *why* it would work. I hope this was the case. Reid -- Reid Ellis 264 Broadway Avenue, Toronto ON, M4P 1V9 Canada rae@gpu.utcs.toronto.edu || rae%alias@csri.toronto.edu || +1 416 487 1383