Topic: type-specifier
Author: alan.feldstein@computer.org ("Alan M. Feldstein")
Date: Wed, 18 Oct 2006 21:23:26 GMT Raw View
I'm having trouble understanding how the following code maps to the
syntax specified in ISO/IEC 14882:2003.
typedef union {
.
struct str_pair_t drive;
.
} yystype;
(The ellipses respresent suppression of detail superfluous to this
discussion.)
This is in the form
typedef type-specifier yystype;
and I'm having no problem with that part.
Therefore,
union {
.
struct str_pair_t drive;
.
}
is a type-specifier, specifically a class-specifier.
From Clause 9,
class-specifier:
class-head { member-specification_opt }
Therefore,
.
struct str_pair_t drive;
.
is a member-specification.
We match Clause 9.2 as follows
member-specification:
member-declaration member-specification_opt
and can conclude that
struct str_pair_t drive;
is a member-declaration.
It is obvious to me that this is not a function-definition,
using-declaration, or template-declaration. The following possible
matches remain:
member-declaration:
decl-specifier-seq_opt member-declarator-list_opt ;
::_opt nested-name-specifier template_opt unqualified-id ;
A nested-name-specifier must have "::" in it (Clause 5), so we conclude that
struct str_pair_t drive;
must match
decl-specifier-seq_opt member-declarator-list_opt ;
There is no comma in the statement, so the optional
member-declarator-list might be (9.2)
member-declarator-list:
member-declarator
Here, the only possible matches are
member-declarator:
declarator pure-specifier_opt
declarator constant-initializer_opt
which are both the same in this case: declarator.
From Clause 8, the only possible match is
declarator:
direct-declarator
and
direct-declarator:
declarator-id
and
declarator-id:
id-expression
::_opt nested-name-specifier_opt type-name
From Clause 5.1,
id-expression:
unqualified-id
qualified-id
and we have a match on
unqualified-id:
identifier
Therefore,
struct str_pair_t drive;
matches
decl-specifier-seq_ identifier ;
where drive is the identifier.
From Clause 7.1,
decl-specifier-seq:
decl-specifier-seq_opt decl-specifier
and
decl-specifier:
storage-class-specifier
*type-specifier*
function-specifier
friend
typedef
I expect
struct str_pair
to be a type-specifier, but I don't see how it matches that.
--
Alan Feldstein
Cosmic Horizon logo
http://www.alanfeldstein.com/
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "Greg Herlihy" <greghe@pacbell.net>
Date: Wed, 18 Oct 2006 20:48:13 CST Raw View
"Alan M. Feldstein" wrote:
> I'm having trouble understanding how the following code maps to the
> syntax specified in ISO/IEC 14882:2003.
>
> typedef union {
> .
> struct str_pair_t drive;
> .
> } yystype;
>
> (The ellipses respresent suppression of detail superfluous to this
> discussion.)
>
>
> This is in the form
>
> typedef type-specifier yystype;
>
> and I'm having no problem with that part.
>....
> I expect
>
> struct str_pair
>
> to be a type-specifier, but I don't see how it matches that.
The presence of the "struct" keyword (usually present for C
compatibility) means that the type-specifier has to be reduced to an
elaborated-type-specifier. An elaborated-type-specifier has the
following syntax:
class-key ::_opt nested-name-specifier_opt identifier
Since the middle two terms are optional, "struct str_pair" matches:
class-key identifier
Greg
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: Alberto Ganesh Barbati <AlbertoBarbati@libero.it>
Date: Wed, 18 Oct 2006 23:45:43 CST Raw View
Alan M. Feldstein ha scritto:
>
> I expect
>
> struct str_pair
>
> to be a type-specifier, but I don't see how it matches that.
>
7.1.5.3/1
elaborated-type-specifier:
class-key ::opt nested-name-specifier opt identifier
class-key ::opt nested-name-specifier opt template opt template-id
enum ::opt nested-name-specifier opt identifier
typename ::opt nested-name-specifier identifier
typename ::opt nested-name-specifier template opt template-id
So "struct str_pair" is an elaborated-type-specifier, matching the first
production rule with class-key == "struct" (see 9/1) and identifier ==
"str_pair" (see 2.10/1).
7.1.5/1
type-specifier:
simple-type-specifier
class-specifier
enum-specifier
elaborated-type-specifier
cv-qualifier
So "struct str_pair" is a type-specifier, matching the fourth production
rule.
HTH,
Ganesh
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]