Monday, June 2, 2008

A subtle optimization by Microsoft

I've spent quite some time with a nasty bug. The code that worked before just stopped working abruptly. The whole class data was getting garbled after a constructor call. Multiple clean rebuilds, full code review of performed changes (over 50 files), tons of coffee even though I quit drinking it.
After staring into disassembled code we've noticed something strange. The constructor was writing proper data into wrong offsets. Mike has got an idea to check the struct member alignment. One project properties had it's Configuration Properties -> C/C++ -> Code Generation -> Struct Member Alignment set to "Default". While the whole solution uses 1 byte struct member alignment.
After a fix, everything worked fine. The question is: How the fuck the alignment could get mysteriously changed in a project that was created by copying the existing project with 1 byte alignment set and actually worked pretty fine until some point? Do they have a keyboard shortcut to change it? Because it's simply not possible to accidentally go to project properties, unfold the Configuration Properties -> C/C++ -> Code Generation branch and then accidentally 6 times double-click on Struct Member Alignment entry.
If I ever figure out how it could happen, I'm gonna hurt the one responsible. Really hard.
0
said thank you for this page

Liked this article? Bookmark/share it with others: Didn't like the article, found a mistake or just want to express your own opinion? Post a comment!

0 comments:

Post a Comment

Have anything to say? Leave a comment!
Too shy or got a too private question? Email me
Alternatively, you can drop me a line on Twitter