typedef is a storage class specifier ?

K

karthikbalaguru

Hi,
I came across the below statement -
" The typedef specifier does not reserve storage
and is called a storage class specifier only for
syntactic convenience ".

But, How is the storage class specifier
and syntactic convenience related ?

Thx in advans,
Karthik Balaguru
 
B

Ben Pfaff

karthikbalaguru said:
" The typedef specifier does not reserve storage
and is called a storage class specifier only for
syntactic convenience ".

But, How is the storage class specifier
and syntactic convenience related ?

typedef is syntactically like a storage class specifier, in that
it is syntactically valid (and invalid) in the same places as a
storage class specifier, but it does not have the semantics of a
storage class specifier.

This is how the storage class specifiers are defined
syntactically:

1 storage-class-specifier:
typedef
extern
static
auto
register

"syntactic convenience", in this case, just means that the folks
who defined the C grammar did not have to add a new production.
If "typedef" wasn't included here, it would be necessary to add
another nonterminal or otherwise complicate the grammar.
 
J

jameskuyper

Ben said:
typedef is syntactically like a storage class specifier, in that
it is syntactically valid (and invalid) in the same places as a
storage class specifier, but it does not have the semantics of a
storage class specifier.

This is how the storage class specifiers are defined
syntactically:

1 storage-class-specifier:
typedef
extern
static
auto
register

"syntactic convenience", in this case, just means that the folks
who defined the C grammar did not have to add a new production.
If "typedef" wasn't included here, it would be necessary to add
another nonterminal or otherwise complicate the grammar.

Let me expand on that, by explain why this is not merely a
coincidence, but an inherent consequence of the way typedefs were
defined.

The basic idea of a typedef is that it looks exactly like the
declaration of a named thing of the type being defined. However,
since it defines an alias for that type, rather than a thing of that
type, a typedef is, in a sense, an alternative to a specified storage
class; it specifies something that is not stored anywhere. As a
result, grouping it syntactically with the things that do identify the
storage location is a natural fit.
 
K

karthikbalaguru

Let me expand on that, by explain why this is not merely a
coincidence, but an inherent consequence of the way typedefs were
defined.

The basic idea of a typedef is that it looks exactly like the
declaration of a named thing of the type being defined.   However,
since it defines an alias for that type, rather than a thing of that
type, a typedef is, in a sense, an alternative to a specified storage
class; it specifies something that is not stored anywhere. As a
result, grouping it syntactically with the things that do identify the
storage location is a natural fit.- Hide quoted text -

Yes, interesting reason for typedef to be
termed as a storage class specifier.

Karthik Balaguru
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top