Question about ubyte x overflow, any safe way?

matheus matheus at gmail.com
Mon Aug 5 18:21:36 UTC 2019


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 
exception.

It's ubyte, but it could be any other data type.

Thanks anyway,

Matheus.



More information about the Digitalmars-d-learn mailing list