I am in the process of refactoring a codebase that is written in C, but I’m using a C++ compiler and I want to use a C compiler.
One thing I stumbled upon is that C++ allows extern
arrays of elements with an incomplete type, while C does not.
For example, the following C program doesn’t compile:
extern struct Foo foos[];
struct Foo {};
int main() {
}
Godbolt demo
Why does C not allow this? C does allow extern
variables with incomplete types. Why are arrays an exception?
7