Checked oveflows in C#

Nick Sabalausky a at a.a
Mon Jan 26 09:54:38 PST 2009


"bearophile" <bearophileHUGS at lycos.com> wrote in message 
news:glk5pj$22rt$1 at digitalmars.com...
> It seems one group of ideas and syntax I did suggest for D weren't so 
> Krazy, after all. I have just found that they can be seen almost equal in 
> C#.
>
> You can read something about them here:
> http://msdn.microsoft.com/en-us/library/a569z7k8.aspx
>
> There is the checked/unchecked keyword that can be used to denote a block 
> of code:
>
> checked {
>    z = x * y;
> }
>
> unchecked {
>    z = x * y;
> }
>
> Or even just an expression:
> z = checked(a + b);
>
> z = unchecked(a + b);
>
> Beside that, you also have a global compiler flag that activates or 
> disables the oveflow checks globally. So if you activate them globally, 
> you can disable them locally, and if you disable them globally you can 
> activate them locally.
>
> As you may remember, I did invent a similar design for D, but:
> - I didn't invent the ability to activate/disable such checks for a single 
> expression. I am not sure how much this can be useful.
> - I did invent a syntax to tell what controls to perform, for example:
> safe(overflow, bounds, ...) { ... }
> unsafe(overflow, bounds, ...) { ... }
>
> Note that for non-English people it's not easy to write the keywords 
> checked/unchecked, that's why I think safe()/unsafe() words are better.
>

Agreed. I've felt for a while that D should copy C#'s checked/unchecked 
system (maybe with your extensions, too). 





More information about the Digitalmars-d mailing list