c++ - The meaning of synonym in typedef -
the following paragraph taken [dcl.typedef]:
within scope of declaration, typedef-name syntactically equivalent keyword , names type associated identifier in way described in clause 8. typedef-name synonym type. typedef-name not introduce new type way class declaration (9.1) or enum declaration does.
the other relevant passage need [dcl.type]
as general rule, @ 1 type-specifier allowed in complete decl-specifier-seq of declaration or in type-specifier-seq or trailing-type-specifier-seq. exceptions rule following: … long can combined long.
in following code, i1 synonym long.
typedef long i1; typedef long i1 i2; thus, expect second line understood typedef long long i2. however, msvc2015rc fails with
error c2146 syntax error: missing ';' before identifier 'i2'
can point part of standard invalidates expectation?
update
my point that, far understand grammar in [dcl.type],
type-specifier: trailing-type-specifier class-specifier enum-specifier trailing-type-specifier: simple-type-specifier elaborated-type-specifier typename-specifier cv-qualifier type-specifier-seq: type-specifier attribute-specifier-seq opt type-specifier type-specifier-seq trailing-type-specifier-seq: trailing-type-specifier attribute-specifier-seq opt trailing-type-specifier trailing-type-specifier-seq a decl-specifier-seq allow sequence of type specifiers long satisfy combination rules. seems me type not same type-specifier though type specified type specifier ;-)
alright, i'll answer.
first, looking @ this:
a typedef-name syntactically equivalent keyword
this means typedef-names follow syntax of keywords. not mean typedef-name equivalent particular keyword. it's new, unique keyword.
then have,
a typedef-name synonym type.
so, given typedef long i1;, "another type"? long int, not long.
in addition, "type"? @ least, type-specifier not type. type-specifier long represents type "long int" (see table 10 of n3337 or table 9 of n4296).
i'll copy comment here:
i1synonym typelong int. not synonym keywordlong. otherwisei1 double,long double.
though perhaps should have said, i1 not synonym type-specifier long, synonym type long int.
Comments
Post a Comment