I just had the worst problem ever in my mixed C/C++ project.
The C code is the production code, the C++ is the testing environment. We are compiling with MinGW GCC, but developing on Qt Creator which has clang as an inline pre-compiler.
In my production code, a data structure that I have been using had its last member become obsolete. I therefore removed it and it became empty. However there is a slew of methods that handle this data structure so I did not want to remove the data structure altogether. Development is ongoing and we might later want to add an element in that data structure after all.
After that my program started crashing badly. I realized that methods were passed a certain value but “saw” a different one from their scope. A pointer was pointing to an address that was one byte off from where it should be. Chaos was omnipresent, as well as a thick cloud of mystery.
Then I saw it. Clang had issued an inline warning about how data structures had size zero in C but size one in C++. I had seen it, but ignored it, thinking “who cares”. Or more accurately, not thinking. But then I came back to it. I tried putting a dummy into the data structure and tadam ! everything was fixed.
The strange thing is, GCC gives no warning on this. It tries to live through it. However I also discovered that empty structs are actually forbidden in C.
So the question is : can I ask GCC to give me an error on empty structs ? I will make it the default compiler behavior in our project. However I can find no such -Werror flag in the GNU man page.