Static structure in C / C ++

static struct K { int x; }; 

Is this valid in C and C ++?

+6
c ++ c syntax
source share
4 answers

Valid in C. Not formed in C ++

In C ++, extern / static specifiers can only be applied to object or function names

Departure

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


+4
source share

In C, it is valid but useless .

In C ++, it is invalid. You can specify a storage class for objects and functions.

+9
source share

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

 namespace { struct K { int x; }; } 

See this topic:

Is static namespace superior to static?

+2
source share
+1
source share

All Articles