Path: utzoo!attcan!uunet!timbuk!cs.umn.edu!ub.d.umn.edu!rutgers!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!swrinde!ucsd!ucbvax!bloom-beacon!eru!hagbard!sunic!kth.se!cyklop.nada.kth.se!news From: d88-jwa@dront.nada.kth.se (Jon W{tte) Newsgroups: comp.sys.mac.programmer Subject: Re: Is Technote #213 wrong? Keywords: stripaddress, 24-bit, 32-bit Message-ID: <1990Oct26.123841.25397@nada.kth.se> Date: 26 Oct 90 12:38:41 GMT References: Organization: Royal Institute of Technology, Stockholm, Sweden Lines: 43 In article Reid Ellis writes: >This regards Technote #213, whose header is as follows: >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)) { ... } Well, if the two pointers come from the same source, at the same time, this will work. But if you have one pointer from a dereferenced locked handle, and one from a dereferenced unlocked handle, or something like that, it won't work, since the address space is 24 bits, and the high 8 bits are kept for state information (under 24bit mode) Pointer arithmetic is performed on all 32 bits, so if you have different state info in the different pointers, you'll get bogus results. To be on the safe side, your code should read: if(StripAddress(ptr2 - ptr1) < sizeof(array)) { ... } Note ! This will always work: { struct foo * a, * b; ... b = &a[index]; while (a < b) { ... a++; } since b is a derivate of (the same pointer as) a; Hope this helps... h+ h+@nada.kth.se "Moof!(tm)"