Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!uwvax!dogie.macc.wisc.edu!csd4.milw.wisc.edu!lll-winken!uunet!portal!cup.portal.com!Tim_CDC_Roberts From: Tim_CDC_Roberts@cup.portal.com Newsgroups: comp.lang.c Subject: Re: Another silly question Message-ID: <18560@cup.portal.com> Date: 19 May 89 22:25:04 GMT References: <17812@cup.portal.com> <2336@Portia.Stanford.EDU> <25671@amdcad.AMD.COM> <1176@mcrware.UUCP> Organization: The Portal System (TM) Lines: 36 In <1176@mcrware.UUCP>, jejones@mcrware.UUCP (James Jones) writes: >A message asserts that surely > > (p + 3) + 5 == p + (3 + 5) > >where p is a pointer, and so it is, but...in general, it might not be. >We turn once again to the canonical counterexample, segmented >architectures, where it's not clear that > > (p - 5) + 6 == p + (-5 + 6) > >since p - 5 might fall off the end of the segment, and after that, all >bets are likely to be off. I disagree with this! I assert that EVEN if the intermediate result goes negative, the final value will be correct, even on segmented architectures. It is true that it might be impossible or even dangerous to dereference the address (p - 5), but we aren't trying to DO that. Example: 32 bit system. Top 12 bits are a segment number, bottom 20 bits are an address. Lets say p is at offset 2 in segment 0x012. p = 0x01200002 p-5 = 0x011ffffd (p-5)+6 = 0x01200003 Yes, the intermediate value is not a valid address, but I don't think that's important. Tim_CDC_Roberts@cup.portal.com | Control Data... ...!sun!portal!cup.portal.com!tim_cdc_roberts | ...or it will control you.