6
static struct K {  int x; };

Is this valid in C and C++?

5
  • 3
    Why not just try it and see? When you find out that it isn't ask what your error is. Commented Mar 5, 2011 at 17:47
  • 4
    You have no access to a compiler or something? Commented Mar 5, 2011 at 17:47
  • 1
    @Darin these days everyone who has access to internet has access to compiler: ideone.com/YqWd8 Commented Mar 5, 2011 at 17:50
  • 8
    I think it's a reasonable question. What one compiler accepts, another may reject, and this doesn't really help to work out whether it's valid C and C++. Commented Mar 5, 2011 at 17:55
  • @Brone In this case, wouldn't any reasonable C compiler accept it and any reasonable C++ compiler reject it? It's certainly a reasonable question; I just get tired of getting excited and then clicking on a link for a question the OP could have answered on their own in about 30 seconds. Commented Mar 6, 2011 at 19:59

4 Answers 4

8

In C, it's valid but useless.

In C++ it's invalid. You can only specify storage class for objects and functions.

Sign up to request clarification or add additional context in comments.

Comments

4

Valid in C. Ill-formed in C++

In C++, specifiers extern/static can only be applied to names of objects or functions

Check out

C.1.5 Clause 7: declarations (7.1.1) ISO C++03


Comments

2

No... That is not valid in C++. An alternative is (C++) : unnamed namespace

namespace 
{
   struct K {  int x; };
}

See this related topic:

Superiority of unnamed namespace over static?

Comments

1

http://ideone.com/YqWd8

http://ideone.com/XtHYy

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.