Another silly question

Tim_CDC_Roberts at cup.portal.com Tim_CDC_Roberts at cup.portal.com
Sat May 20 08:25:04 AEST 1989


In <1176 at mcrware.UUCP>, jejones at 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 at cup.portal.com                | Control Data...
...!sun!portal!cup.portal.com!tim_cdc_roberts |   ...or it will control you.

 



More information about the Comp.lang.c mailing list