Joe said:
Keith said:
Chris Dollin said:
Joe Wright wrote:
Sure. name == identifier. Isn't x[2] an identifier?
That was a joke, right? No, x[2] certainly isn't an identifier.
Keith, I have snipped your response to Chris Dollin. I fear we're
getting off (my) topic. I'm using K&R2 as reference. A4. "Identifiers or
names refer to a variety of things (amonng them) objects." "An object,
sometimes called a variable, is a location in storage..".
A prior message in this thread suggests given 'int a[10];' a is an
object and a variable and a[2] is neither. a is an object, an array 10
of int but is a variable? No says I, the modifiable lvalue thing. But
a[2] is an object of type int and is variable.
If a[2] refers to a location in storage of an object or variable, why
isn't it an identifier?
Because "referring to the location in storage of an object or
variable" is a matter of semantics, and identifiers are defined in
terms of syntax, not semantics. Nor is there any particularly close
connection between the syntax of identifiers and the semantics you
describe. Some identifiers do identify an object, but many identify
other things: for instance macros, functions, structure tags,
enumeration constants, or statement labels. Furthermore, not
everything that does refer to an object is an identifier; some of the
things that do so are expressions, as is true in this case.
Section 6.4.2.1p1 specifies, with great precision, what an identifier
is:
_identifier_:
_identifier-nondigit_
_identifier identifier-nondigit_
_identifier digit_
_identifier-nondigit_:
_nondigit_
_universal-character-name_
other implementation-defined characters
_nondigit_: one of
_ a b c d e f g h i j k l m
n o p q r s t u v w x y z
A B C D E F G H I J K L M
N O P Q R S T U V W X Y Z
_digit_: one of
0 1 2 3 4 5 6 7 8 9
Paragraph 3 explains the "other implementation-defined characters":
"An implementation may allow multibyte characters that are not part of
the basic source character set to
appear in identifiers; which characters and their correspondence to
universal character names is implementation-defined."
The characters '[' and ']' do not meet the requirements for qualifying
as either "digits" or "non-digits". Since they are part of the basic
source character set, they also can't qualify under the 'other'
category. Therefore they cannot appear anywhere in an identifier.
The C standard describes a[2] as a postfix-expression consisting of
the identifier "a", which parses as a postfix-expression in it's own
right, the subscript operator consisting of the tokens "[" and "]",
and the integer literal "2" which parses as an expression in this
context. See 6.5.2p1:
_postfix-expression_:
....
_postfix-expression_ [ _expression_ ]