Struct Declaration: Valid initializer in declaration?
c, declaration, definition, struct
Solution
I don't think it's allowed. You need to specify the value for the variable, not the struct:
struct foo { size_t var; };
struct foo myfoo = { 1 };
As for the IDE allowing it, the obvious possibility would be that the code is really a little different, such as:
struct foo { static const size_t var = 1; }
...and the IDE is compiling it as C++ rather than C.
Problem
I'm declaring a struct in the IDE (Netbeans) like this: `struct foo { size_t var = 1; }` And the IDE says its legal. I compile the project (its a static lib..) and the compiler says its legal (does not moan or throw). Now since I'm just testing the syntax at this point I have to ask someone who might know if this will actually work when I go to declare a struct of this tag in my procedures like this: `struct foo myfoo;` So the question is: Is that a valid initalizer? (`size_t var = 1`) or is the compiler just stroking my ego here? I haven't found anything on google or in documentation like this so I'm guessing it doesn't work the way I hope it will. *edit So me and the Good 'ol boys here @SO figured out that it will compile in a debug configuration but not a release configuration. Who says one head is better than a couple thousand? :D