The other day at work we ran into a nasty little bug that was quite tricky and chewed up quite a few hours of a few people’s time. So I thought that as a service to you, my loyal reader, I would post about it and warn you of this tricky little issue that deals with how gcc (or at least some versions of it, including the ancient version that we happen to be using) treats empty structs differently, depending on whether you’re compiling as C or C++…
…Except that my colleague Chris has already blogged about it, so it would be pointless for me to rehash it when he has already said it quite well. So I’ll just link to him.
Compiler bugs are the worst, because we trust compilers so much. They’re pretty much innocent until proven guilty and when I have a problem, they are the last thing that I suspect. Which means that when a compiler bug hits, you’re likely to spend many hours looking carefully for the problems in your own code, never suspecting the compiler as the culprit. Heck, you probably will find a few problems in your own code and then spend a few hours fixing them, only to find that these problems were problems but not the problem that you were trying to solve. Compiler bugs tend to be catastrophic problems that trash your stack and the like, often rendering tools like debuggers and memory checkers marginally useful at best.
I am certainly going to be very wary of empty structs after this experience.