Integer overflow and underflow semantics

renoX renozyx at gmail.com
Mon May 21 02:11:19 PDT 2012


On Friday, 18 May 2012 at 20:01:15 UTC, Paul D. Anderson wrote:
> On Friday, 18 May 2012 at 19:59:01 UTC, Paul D. Anderson wrote:
>> On Sunday, 6 May 2012 at 16:27:34 UTC, Alex Rønne Petersen 
>> wrote:
>>> On 05-05-2012 06:57, Alex Rønne Petersen wrote:
>>>> Hi,
>>>>
>>>> I don't think the language really makes it clear whether 
>>>> overflows and
>>>> underflows are well-defined. Do we guarantee that for any 
>>>> integral type
>>>> T, T.max + 1 == T.min and T.min - 1 == T.max?
>>>>
>>>> This is relevant in particular for GDC and LDC since they 
>>>> target a lot
>>>> of weird architectures.
>>>>
>>>
>>> Can anyone give a definitive answer to this or at least 
>>> confirm that it is an open issue?
>>
>> I don't have the reference at the moment but the C99(?) 
>> standard requires wraparound behavior by UNSIGNED integer 
>> values. I don't know if there is an equivalent requirement for 
>> signed values.
>
> Sorry, it's C++:

It's both C and C++ for unsigned integer.
Signed is undefined, unsigned is 'wraparound'.

Both sucks for the default behaviour IMHO : premature 
optimisation..

renoX




More information about the Digitalmars-d mailing list