当在C ++中的“标识符”一个“名称”? [英] When is an 'identifier' a 'name' in C++?

查看:177
本文介绍了当在C ++中的“标识符”一个“名称”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当一个'标识'在C ++中称为名称?我主要读的'名任期在本例中过于用来代替标识:

When is an 'identifier' called a 'name' in C++? I mostly read that the term `name' is used overly instead of 'identifier' as in the example:

struct S { int i };
S thing1;

在这种情况下,是 thing1 A的名称标识符的?或者是术语标识符'和'名'是类似的?在C语言中,有一个使用期限'名'的引用对象时?

In this case, is the thing1 a name or identifer? Or are the terms 'identifier' and 'name' are analogous? In C, is there a use of the term 'name' when referring to an object?

推荐答案

在C ++中,长期的标识的仅仅是一个数字,字母顺序和 _ ,而不是开始以数字。这样的的标识的可以在任何地方出现,不具备的确定的任何东西,尽管它的名字(没有双关语意)。

In C++, the term identifier is just a sequence of digits, letters and _, not starting with a digit. Such an identifier can appear anywhere, and doesn't have to identify anything, despite its name (no pun intended).

术语的名称的关联具有一定的语法结构意义。 C ++的规范说,下面的文法的一个构造是一个名字,如果它表示一个实体(是的对象的,一个的的,一个的模板的和等等)或一个标签(在这里你可以跳到与转到

The term name associates a meaning with a certain grammar construct. The C++ spec says that one of the following grammar constructs is a name if it denotes an entity (an object, a class, a template and so on) or a label (where you can jump to with goto)


  • 标识

  • 模板id 的(标识符< ...> 运营商功能-ID&LT ;. ..> 文字运营商-ID< ...> ,如富< INT&GT ;

  • 转换功能-ID 的(运营商类型,如运营商INT

  • 运营商功能-ID 的(操作符@ ,如运营商+

  • 文字运营商-ID 的(运营商,标识符,如运营商,_foo

  • identifier
  • template-id (identifier <...>, operator-function-id <...> and literal-operator-id <...>, as in foo <int>).
  • conversion-function-id (operator type, as in operator int)
  • operator-function-id (operator @, as in operator +)
  • literal-operator-id (operator "" identifier, as in operator "" _foo)

有关每个这些构建体,该规则的时的名称是作为另一个名字,定义不同的相同:对于标识符,两个名字是相同的序列是相同的(这仅是一个词汇比较)。为形式的名的转换功能-ID 的他们是相同的,如果所使用的类型相同类型(因此这是一个语义比较)。

For each of these constructs, the rule when a name is the same as another name is defined differently: For identifiers, two names are the same of the sequence is the same (this is only a lexical comparison). For names of form conversion-function-id they are the same if the type used is the same type (so this is a semantic comparison).

正如你在例子中看到的文字运营商-ID 的,非终端的标识的可能出现在地方语法它是不是一个名字。所以,不是每一个的标识的是一个名字,而不是每名是的标识的。在这个例子的模板id 的,我们有一个嵌套使用的名称。 ...&GT;在&LT的构造分别为再次的名字,因为他们表示声明的模板。

As you can see in the example of literal-operator-id, the non-terminal identifier can appear in the grammar in places where it is not a name. So not every identifier is a name, and not every name is an identifier. In the example of template-id, we have a nested use of names. The constructs before the <...> respectively are names again, as they denote declared templates.

这篇关于当在C ++中的“标识符”一个“名称”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆