{"id":110645,"date":"2024-12-16T07:00:00","date_gmt":"2024-12-16T15:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=110645"},"modified":"2024-12-16T09:04:10","modified_gmt":"2024-12-16T17:04:10","slug":"20241216-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20241216-00\/?p=110645","title":{"rendered":"Why do we have header files <CODE>&lt;pshpackN.h&gt;<\/CODE> and <CODE>&lt;poppack.h&gt;<\/CODE> instead of just issuing the pragma directly?"},"content":{"rendered":"<p>When Windows header files need to adjust structure packing, they use the <code>&lt;pshpackN.h&gt;<\/code> and <code>&lt;poppack.h&gt;<\/code> header files. But why bother? Why not just issue the <code>#pragma pack(push, N)<\/code> and <code>#pragma pack(pop)<\/code> directly?<\/p>\n<p>The <code>#pragma pack<\/code> directive is a Microsoft compiler extension. It is not part of the C or C++ standard. The <code>&lt;pshpackN.h&gt;<\/code> and <code>&lt;poppack.h&gt;<\/code> headers are used so that compiler vendors can provide substitute headers which generate directives that work for their compilers.<\/p>\n<p>For example, <a href=\"https:\/\/github.com\/Alexpux\/mingw-w64\/blob\/d0d7f784833bbb0b2d279310ddc6afb52fe47a46\/mingw-w64-tools\/widl\/include\/pshpack1.h\"> here is one example of a replacement header file<\/a> that records the structure packing stack in preprocessor symbols.<\/p>\n<p><b>Related reading<\/b>: <a title=\"What are anonymous structs, and more importantly, how do I tell windows.h to stop using them?\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20170907-00\/?p=96956\"> What are anonymous structs, and more importantly, how do I tell <code>windows.h<\/code> to stop using them<\/a>?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Because the pragma may not work everywhere.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[26],"class_list":["post-110645","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-other"],"acf":[],"blog_post_summary":"<p>Because the pragma may not work everywhere.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/110645","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=110645"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/110645\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=110645"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=110645"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=110645"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}