Why do java, c# and C have no scope?

ADA, Pascal, and many other languages support range, a subtype integer approach

I know that it is impossible to statically verify that variables defined in a scope will not "overflow" the runtime, that is, due to poor input, but I think something can be done I thought of the design by contract method (Eiffel) and spec # (C # contracts) and gave a more general solution

Is there a simpler solution to check static outreach allocation at least at C, c# and Java compile time? Some kind of static assert?

Editor: I understand that "scope" can be used for different purposes:

>Iterator > enumerator > integer subtype

I will focus on the latter, because former can be easily mapped in C * I think of a closed set of values, like music volume, that is, a range from 1 to 100 I want to increase or decrease a value I want a compilation error to prevent static overflow, as follows:

volume=rangeInt(0,100);
volume=101;  // compile error!
volume=getIntFrominput(); // possible runtime exception

thank you.

Solution

In fact, sub - range types are not practical We don't often allocate fixed length arrays, and there is no reason for fixed size integers Usually we see fixed size arrays as an enumeration, and we have a better (although "heavier") solution

Subtypes also complicate the type system Introducing constraints between variables is more useful than fixing constants

(it is mandatory to mention that integers should be of any size in any sensible language.)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>