So, say I have the following C++ header, testheader.h
:
struct mystruct
{
struct myinnerstruct
{
int x;
} astruct;
};
struct myinnerstruct
{
int x;
};
and the following C++ source, test.cpp
:
#include "testheader.h"
using namespace std;
int main()
{
return 0;
}
g++ gives no issues during compile/link.
Now, if I have the same header, but instead of the C++ source, a C source file test.c
:
#include "testheader.h"
int main()
{
return 0;
}
And I compile with gcc, I get the following error:
error: redefinition of struct myinnerstruct
So, I gather that the scope of the C version is the translation unit, and the C++ version is block scoped? Can someone confirm this is the case, and maybe give me a reason of why it makes sense? I'm doing some mixing of C and C++ code, and this is giving me quite a bit of trouble.
Any insight is greatly appreciated. Thanks!