December 16th, 2010

Why does SHCOLUMNINFO have unusually tight packing?

Alternate title: News flash: Sometimes things happen by mistake

rbirkby asks why the SHCOLUMNINFO structure has 1-byte packing. “Was the expectation that there would be so many columns in a details view that the saving would be worthwhile?”

Hardly anything that clever or ingenious. It’s just the consequence of a mistake.

When the SHCOLUMNINFO structure was added to the header file in the Windows 2000 timeframe, it was added with no specific packing directive. But it turns out that there was a specific packing directive; it just wasn’t obvious. Near the top of the shlobj.h header file was the following:

#include <pshpack1.h>   /* Assume byte packing throughout */

(There was of course a matching #include <poppack.h> at the bottom.) This set the default packing for the entire header file to byte packing instead of natural alignment.

By the time this mistake was identified, it was too late. Windows 2000 had already shipped, byte packing and all. And once the code ships, it’s done. You’re stuck with it.

Sorry.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.