#include <stdio.h>
struct s {int;};
int main()
{
printf("Size of 'struct s': %i\n", sizeof(struct s));
return 0;
}
Microsoft C compiler (cl.exe) does not want compile this code.
error C2208: 'int' : no members defined using this type
GNU C compiler (gcc -std=c99) compiles this code...
warning: declaration does not declare anything
...and displays the result:
Size of 'struct s': 0
This means that struct s
in gcc are complete type and cannot be redefined.
Does this means that the complete type can have zero size?
Also, what means the message declaration does not declare anything
if this declaration declares the complete struct?
Here is the proof that the struct s
is a complete type in (gcc -std=c99).
#include <stdio.h>
struct s {int;};
struct S {
struct s s; // <=========== No problem to use it
};
int main()
{
printf("Size of 'struct s': %i\n", sizeof(struct s));
return 0;
}
undefined behavior
in language specifctions. Undefined behavior at runtime or undefined behavior at compile time. – mezoni