John Stracke and the Compiler Bug

(Warning: the geek quotient of this page is extremely high.)

At a former job, I was working under Windows 3.1, developing with Borland C++ Professional 3.0. I started having odd crashes, which I couldn't figure out: every time I called a certain method, it crashed. Eventually, out of desperation, I tried moving my nested classes out into global scope (on the theory that there might be a bug in nested class support); amazingly enough, it worked. Move them back in, crash. So, I tried moving out just the one whose method was crashing; sure enough, that worked. Aargh. OK, well, I had a fix...but I wanted to understand the problem. Eventually I wound up telling the compiler to produce assembly code (as text, that is) so I could look at what was going on. OK, nothing seems to be wrong with that method...what about the place where it's called...gibber, gibber. It turned out that the caller wasn't passing any parameters! What's more, the method's munged name seemed to have been truncated to...63 characters...click! Maybe we're running up against a length limit...so I tried shortening the name (I was using lots of long names in that code--and nested classes were named with a name path, which exacerbated the problem). Yup, a shorter name fixed it. Obviously, despite the standard's declaration that there could be no length limits, and the documentation's claim that the limit was 255 characters, the linker really had a limit of 63, so the compiler had a workaround to truncate names to 63, and the workaround had a bug that kept parameters from being passed in.

Well, groan. I reported it to Borland (never heard anything back), and set about shortening my names. Problem solved--but it changed my expectations; I wasn't quite so surprised, a few months later, when the compiler started crashing (and corrupting the so-called OS). But that's another story. :-)

(Postscript, February 2003: Now that I have a job writing a compiler, I have a lot more sympathy for the people who wrote the Borland compiler. Users keep writing code that does insanely complicated stuff, stuff I would never have thought to test, and they expect it to work, just because the spec says it should. The nerve! ;-)

Home SCA Geekery Books Thoughts Send mail Mastodon