On Thu, Aug 11, 2011 at 12:15 PM, Richard Guenther
<richard.guent...@gmail.com> wrote:
> On Thu, Aug 11, 2011 at 7:13 PM, Joe Buck <joe.b...@synopsys.com> wrote:
>> On Thu, Aug 11, 2011 at 09:05:19AM -0700, Florian Merz wrote:
>>> If I remember the standard correctly, pointer subtraction is valid if both
>>> pointers point to elements of the same array or to one past the last element
>>> of the array. According to this 0x80000000 - 0x7FFFFFFF should be a valid
>>> pointer subtraction with the result 0x00000001.
>>>
>>> But if the subtraction is treated as a signed, this would be an signed 
>>> integer
>>> overflow, as we subtract INT_MAX from INT_MIN, which surely must overflow, 
>>> and
>>> the result therefore would be undefined.
>>
>> It is true that the C and C++ languages make signed integer overflow
>> undefined, but that's for actual integer types as declared by the user.
>> For pointers, though the subtraction has to be signed (because, for two
>> pointers, either can can come later in the address space), this signed
>> subtraction has to be defined to work in a two's complement fashion (so
>> the wraparound in your example case works reliably).
>
> Of course GCC can't (yet) do both at the same time.

yes, but GCC should mark its internal artifacts so that it surely distinguishes
user-provided abstractions (which may be subjected to harsh treatments)
from its own blessed babies.

>  Thus we have to
> use unsigned arithmetic when we want two's complement arithmetic.

Reply via email to