On Mon, 26 Jan 2009 20:54:38 +0300, Nick Sabalausky <[email protected]> wrote:
"bearophile" <[email protected]> wrote in message
news:[email protected]...
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).
I agree. I have proposed the same a few times in the past.
'checked' can be implemented in a library (to some degree) but a full-fledged
solution needs compiler support.