我们什么时候说两个标识符具有相同的范围?(When do we say that two identifiers have same scope?)

编程入门 行业动态 更新时间:2024-10-18 06:06:26
我们什么时候说两个标识符具有相同的范围?(When do we say that two identifiers have same scope?)

C标准定义了两个标识符具有相同的范围,当且仅当它们的范围终止于同一点时。 并继续说明:

结构,联合和枚举标记具有在声明标记的类型说明符中标记出现之后开始的范围。 每个枚举常量都具有在枚举器列表中定义枚举器出现之后开始的范围。 任何其他标识符的范围都在其声明者完成之后开始。

这是否意味着正式调用两个标识符以具有相同的范围,即使它们的范围的开头不匹配?

The C standard defines that two identifiers have same scope if and only if their scope terminates at the same point. And goes on further to state that:

Structure, union, and enumeration tags have scope that begins just after the appearance of the tag in a type specifier that declares the tag. Each enumeration constant has scope that begins just after the appearance of its defining enumerator in an enumerator list. Any other identifier has scope that begins just after the completion of its declarator.

Does it mean that two identifiers are formally called to have same scope even if the beginning of their scope doesn't match ?

最满意答案

是的,这是一种合理的思考方式。 否则,没有两个标识符具有相同的范围!

{ int a; int b; }

在上面, a和b的范围从不同的点开始,但我们当然希望将它们视为在同一范围内!

Yes, that's a reasonable way of thinking about it. Otherwise no two identifiers would have the same scope!

{ int a; int b; }

In the above, the scopes of a and b begin at different points, but surely we want to think of them as being in the same scope!

更多推荐

本文发布于:2023-07-04 17:12:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1026976.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标识符   什么时候   两个   scope   identifiers

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!