关于“范围”在艾达
Ada 中的以下源代码行
type Airplane_ID is range 1..10;
可以写为
type Airplane_ID is range 1..x;
,其中 x 是变量?我问这个是因为我想知道 x 的值是否可以修改,例如通过文本输入。提前致谢。
The following source code line in Ada,
type Airplane_ID is range 1..10;
, can be written as
type Airplane_ID is range 1..x;
, where x is a variable? I ask this because I want to know if the value of x can be modified, for example through text input. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不,范围的边界都必须是静态表达式。
但是您可以声明具有动态边界的子类型:
No, the bounds of the range both have to be static expressions.
But you can declare a subtype with dynamic bounds:
我假设你的意思是改变 x 的值会以动态的方式改变范围本身;如果是这样,那么严格来说,不……但这并不是全部答案。
你可以这样做:
I assume that you mean such that altering the value of x alters the range itself in a dynamic-sort of style; if so then strictly speaking, no... but that's not quite the whole answer.
You can do something like this:
不可以。Ada 范围声明必须是常量。
No. An Ada range declaration must be constant.
正如其他答案所提到的,您可以按照自己想要的方式声明范围,只要它们是在某种块中声明的 - “声明”块,或者过程或函数;例如:
As the other answers have mentioned, you can declare ranges in the way you want, so long as they are declared in some kind of block - a 'declare' block, or a procedure or function; for instance: