Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Name of entire group of four C++ declaration symbols?

Tags:

c++

syntax

My understanding is that generically the entire group of non-alphanumeric characters like *, ?, ;, #, etc. can be called punctuators. However, in an expression like

    3*4

the * is specifically known as an "operator" whereas in a declaration like

    int *p;

the * is not an operator but instead merely indicates that p is a pointer. Similarly the 3 additional symbols &, [], and () are not called operators when used in declarations. I know what all of these symbols mean in their various contexts, how they are pronounced, and what they do, but is there a specific name for this entire group of four symbols when used in declarations? I've always called them "attributes" for lack of anything better and I can't find anything specific in the language standards regarding a name for the group.

like image 531
BenevolentDeity Avatar asked Nov 08 '17 01:11

BenevolentDeity


2 Answers

As you already know that the characters like *, ?, ;, # etc. are known as Punctuator in C and C++.

A punctuator is a token that has syntactic and semantic meaning to the compiler, but the exact significance depends on the context. A punctuator can also be a token that is used in the syntax of the preprocessor.

Punctuators are not operators or identifiers. Some characters can be used either as a punctuator or as an operator, or as part of an operator. The context of the occurrence specifies the meaning.

From C Standard#6.4.6:

A punctuator is a symbol that has independent syntactic and semantic significance. Depending on context, it may specify an operation to be performed (which in turn may yield a value or a function designator, produce a side effect, or some combination thereof) in which case it is known as an operator (other forms of operator also exist in some contexts). An operand is an entity on which an operator acts.

Their meaning is different based on the context in which they have been used. So, there is no specific name for the entire group of four symbols and if you want to call them with a single word then, I believe, the word punctuator is the most appropriate word.

Additional : Most of the punctuator are common in C and C++. But C++ is having some additional punctuators like ::, .*, new, delete etc.

like image 183
H.S. Avatar answered Nov 18 '22 05:11

H.S.


but is there a specific name for this entire group of four symbols when used in declarations?

Sort of. The grammatical construct that references these symbols in declarations are "declarators". This name isn't really used outside of standard discussions however; there just isn't much need to refer to declarator symbols as a group.

Also, there are more declarator symbols than that. In C, there is () (for function declarations). C++ gives us ... (parameter pack declarations), and && (r-value reference).

like image 3
Nicol Bolas Avatar answered Nov 18 '22 06:11

Nicol Bolas