Path: utzoo!attcan!uunet!mailrus!uwm.edu!ux1.cso.uiuc.edu!csrd.uiuc.edu!usenet From: bruner@sp15.csrd.uiuc.edu (John Bruner) Newsgroups: comp.sys.mac.programmer Subject: StripAddress and pointer arithmetic Message-ID: <1990May25.194025.9751@csrd.uiuc.edu> Date: 25 May 90 19:40:25 GMT Sender: usenet@csrd.uiuc.edu (news) Reply-To: bruner@sp15.csrd.uiuc.edu (John Bruner) Organization: CSRD, University of Illinois Lines: 32 I've just read the technical note on StripAddress (#213, April 1990). On the second page under the (sub)heading "Ordered Address Comparison" it says If you need to sort by address or do any other kind of ordered address comparison, you need to call _StripAddress on each address before doing any ordered comparisons (>, <, >=, <=). Remember, even though the CPU only uses the lower 24 bits in 24-bit mode, it still uses all 32 bits when performing arithmetic operations. Taken literally, this means that it is unsafe to write struct something *p, things[64]; for (p = things; p < things + 64; p++) ... because one can't rely upon the comparison "p < things+64" working. This type of expression is very common in C (and is sanctioned by the ANSI standard). I don't really believe this will fail, because the high bits in the expressions "things" and "things + 64" will almost certainly be the same (unless it would wrap in a 24-bit address space). I believe I understand what will and will not behave as expected, but I think it should be spelled out better. The way I read this technical note the Macintosh cannot (efficiently) support an ANSI-compliant implementation of C. -- John Bruner Center for Supercomputing R&D, University of Illinois bruner@uicsrd.csrd.uiuc.edu (217) 244-4476