[Gambas-user] Overflow Errors with Gambas 3.18 and Master

Benoit Minisini benoit.minisini at gambas-basic.org
Sat Jan 14 19:14:00 CET 2023


Le 14/01/2023 à 11:54, Claus Dietrich a écrit :
> 
> Am 14.01.23 um 00:20 schrieb Benoit Minisini:
>> ClockFaceColor + 16777216 * ClockFaceOpacity -> This is the code that 
>> overflows.
>>
>> You must replace this wrong code by:
>>
>> Color.SetAlpha(ClockFaceColor, ...) 
> 
> Thanks for the advise - will be changed.
> 
> However, the code line
> Paint.Brush = Paint.Color(ClockFaceColor + 16777216 * ClockFaceOpacity)
> which used to work until 3.17.3 generates a color value from &H00nnnnnn 
> to &HFFnnnnnn which is within the range of colors which are allowed. 

Yes, but the computation overflows. This was ignored by Gambas 3.17.3, 
and is now detected by Gambas 3.18.0.

The fact that the overflow leads to the expected result relies on an 
implicit behaviour of the underlying CPU. But the C standard explicitly 
says that arithmetic overflow lead to unspecified results. In other 
words, this is an error to write code that relies on that specific CPU 
behaviour.

In practice, it's not a big deal, as the only CPUs I'm aware of where 
oveflow does not always behave the "expected" way are Cray Computer CPUs.

Anyway, to let your old project run as before, there is now a 
'System.IgnoreOverflow' property that restores the old behaviour. Just 
set this property to TRUE at the beginning of your program.

Regards,

-- 
Benoît Minisini.



More information about the User mailing list