On Monday, 5 August 2019 at 18:21:36 UTC, matheus wrote:
On Monday, 5 August 2019 at 01:41:06 UTC, Ali Çehreli wrote:
Two examples with foreach and ranges. The 'ubyte.max + 1'
expression is int. The compiler casts to ubyte (because we
typed ubyte) in the foreach and we cast to ubyte in the range:
Maybe it was a bad example of my part (Using for), and indeed
using foreach would solve that specific issue, but what I'm
really looking for if there is a flag or a way to check for
overflow when assigning some variable.
ubyte u = 260; // Here should be given some warning or throw
It's ubyte, but it could be any other data type.
Yes, no question. It's checkedint that you should use. It was
written exactly for that purpose.