array/Array: "hard" bounds checking

TheFlyingFiddle none at none.com
Thu Feb 22 20:07:32 UTC 2018


On Thursday, 22 February 2018 at 12:50:43 UTC, ag0aep6g wrote:
> On 02/22/2018 10:39 AM, bauss wrote:
>> On Thursday, 22 February 2018 at 05:22:19 UTC, TheFlyingFiddle 
>> wrote:
>>>
>>> Eg:
>>>
>>> uint a = 3;
>>> int b = -1;
>>>
>>> assert(a > b); //No idea what should happen here.
>> 
>> This is what happens:
>> 
>> assert(cast(int)a > b);
>
> Nope. It's `assert(a > cast(uint)b);`.

These two posts kind of proved my point :D. And that is why you 
should never mix signed and unsigned integers. A good thing is 
that dscanner static analysis will warn you about this stuff (in 
simple cases at-least).


More information about the Digitalmars-d-learn mailing list