Message Font: Serif | Sans-Serif
No. of Recommendations: 0
Over the last few days I have been dealing with a very mysterious bug that showed up in a product I just shipped. After a lot of detective work, and some help from a very smart colleague and friend, it became clear that it's that very rare bird, a bona fide compiler bug.

You likely know how it is. You get a bug that you can't understand, that makes no sense at all, where the computer goes all haywire when your code is simple, straightforward, and everyone who looks at it says it's right. Might be a compiler bug, right? But if you come right out and call it that, somebody will immediately prove that it's not, it's an error on your part, and you're humiliated.

But this one, hey, this IS a compiler bug. You've got a standard type representing a "size" -- width and height of a rectangle. It's just a C struct containing two floats. BUT if you access the height member with someSize.height, you don't get the height. You get the width! It drove me nuts until my pal realized that was happening. If you access the width with someSize.width, it works fine. And if you assign a value to the height with someSize.height = aValue, that works fine too. It's only when you take the value of the height that something goes wrong.

I worked around it by taking the address of someSize, then using pointer arithmetic to get the height member of the struct. That was completely successful.

But what IS the compiler bug? There are other standard structs containing two floats, such as a type representing a point, with two floats for X and Y. No bug there. Just this one "size of a rectangle" type.

So I'm guessing that someone decided to put an optimization in the compiler just for this specific type, and got it wrong. And then they fixed it, but they forgot a corner scenario like mine: code that is compiled to run on several different versions of the OS works fine on most of them, but fails in one scenario: code compiled with a "final build" configuration, running on a system with an old OS. And my customer base uses a lot of old hardware that only supports old versions of the OS.

OOOh, I'm gonna file such a bug report.
Print the post  


When Life Gives You Lemons
We all have had hardships and made poor decisions. The important thing is how we respond and grow. Read the story of a Fool who started from nothing, and looks to gain everything.
Contact Us
Contact Customer Service and other Fool departments here.
Work for Fools?
Winner of the Washingtonian great places to work, and Glassdoor #1 Company to Work For 2015! Have access to all of TMF's online and email products for FREE, and be paid for your contributions to TMF! Click the link and start your Fool career.