declaration of just a type with storage class specifier

L

Luca Forlizzi

In the book "C A reference Manual" (5th edition), the authors state
that a declaration like the following is invalid:

static struct s { int a; int b; } ;

I can't find in the standard which constraint or semantics is
violated.
Can you help?
 
T

Tim Rentsch

Luca Forlizzi said:
In the book "C A reference Manual" (5th edition), the authors state
that a declaration like the following is invalid:

static struct s { int a; int b; } ;

I can't find in the standard which constraint or semantics is
violated.
Can you help?

My best understanding is that it is legal and well-defined.
Certainly it's legal and well-defined without the 'static'
storage-class specifier, and a grep on 'storage.class' didn't
turn up anything wrong that I could see.
 
L

Luca Forlizzi

My best understanding is that it is legal and well-defined.
Certainly it's legal and well-defined without the 'static'
storage-class specifier, and a grep on 'storage.class' didn't
turn up anything wrong that I could see.

that's also my understanding. I also think that the presence of
'static' has no effect on the semantics of the declaration (as
suggested by the book authors). Do you agree?
 
L

Luca Forlizzi

Luca said:
Vincenzo Mercuri wrote:
so it has not sense [...]
sorry, i meant 'it makes no sense'
I agree that it makes no sense, but how one concludes that it is
invalid?

Beware that 'C: A Reference Manual' says that it is
"nonsensical and (in Standard C) illegal" where Standard C
means C89 (see page 4, 5th edition).
Now I can't say if it is illegal in C89, (i dont have the
Standard) but I can just say it is nonsensical in C99

Hi Vincenzo,

I checked C89 and I don't see in it anything that renders such a
declaration invalid. I think it is valid and a well-defined
declaration.
And that it has a meaning, because it declares the new struct type and
its tag.
Because of that, I wouldn't call it nonsensical. The only
"nonsensical" part, is that it uses a storage-class specifier that
could be omitted without changing the declaration's meaning. There are
cases like this. For instance in

extern int f(void);

the storage-class specifier could be omitted without changing
semantics, as well (so I think).
Would you call it nonsensical, too ?
 
T

Tim Rentsch

Luca Forlizzi said:
that's also my understanding. I also think that the presence of
'static' has no effect on the semantics of the declaration (as
suggested by the book authors). Do you agree?

Yes, reading the relevant sections (6.2.2 and 6.2.4, IIRC), makes
it clear that the result is not changed by adding 'static'.
 
S

Shao Miller

Yes, reading the relevant sections (6.2.2 and 6.2.4, IIRC), makes
it clear that the result is not changed by adding 'static'.
Agreed. Functions and objects have linkage. Objects have storage
duration. A 'struct' tag has neither of these, but "storage class
specifier" in the syntax is (ab)used to include 'typedef'. One might
wish to use 'typedef' along with their 'struct' declaration.
 

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,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top