Extending from this question
I am having trouble to understand this code.
struct foo myfoo; // --> Is it forward declaration or object creation. ?
struct foo
{
int a;
};
int main()
{
return 0;
}
In the code marked arrow --> Is it forward declaration or object creation. ?
If that is forward declaration then what is struct foo; called ? If it’s object creation or instantiation then how can it create object before struct definition.
On gcc compiler its working fine but other compiler gives error.
gcc -Werror -Wall tst.c -o tst
Any suggestion or explanation about this behavior of gcc? I could not have found anywhere it as documented.
Looks like tentative definition of
myfooand because the definition of the struct is provided you get no error.clang provides a comprehensive diagnostic when the type in not defined.
I don’t think its a gcc bug, clang as well as comeau online is compiling the code.
$6.9.2/2