{"id":22993,"date":"2008-03-26T10:00:00","date_gmt":"2008-03-26T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2008\/03\/26\/why-are-structure-names-different-from-their-typedef-names\/"},"modified":"2008-03-26T10:00:00","modified_gmt":"2008-03-26T10:00:00","slug":"why-are-structure-names-different-from-their-typedef-names","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20080326-00\/?p=22993","title":{"rendered":"Why are structure names different from their typedef names?"},"content":{"rendered":"<p>\nIn Windows header files, many structures\nare declared like this:\n<\/p>\n<pre>\ntypedef struct tagXYZ {\n ...\n} XYZ;\ntypedef struct _XYZ {\n ...\n} XYZ;\n\/* there are other variations, too *\/\n<\/pre>\n<p>\nWhy is the structure name different from typedef name?\n<\/p>\n<p>\nThis is a holdover from very early versions of the C language\nwhere structure tags, union tags,\nand typedefs were kept in the same namespace.\nConsequently, you couldn&#8217;t say\n<code>typedef struct XYZ { ... } XYZ;<\/code>.\nAt the open brace, the compiler registers <code>XYZ<\/code>\nas a structure tag name, and then when <code>XYZ<\/code> appears\na second time, you get a redeclaration error.\nThe standard workaround for this was to make the structure tag name\na minor modification of the typedef name,\nmost typically by putting the word <code>tag<\/code> in front.\n<\/p>\n<p>\nThe C language standardization process separated the structure\nand typename name spaces, so this workaround is no longer necessary,\nbut it doesn&#8217;t hurt either.\nBesides, even if new structures followed the\n<code>typedef struct XYZ { ... } XYZ;<\/code> pattern,\nyou would just have people asking,\n&#8220;Why do some structures in <code>winuser.h<\/code> use\nthe <code>tagXYZ<\/code> pattern and others use the <code>XYZ<\/code>\npattern?\nWhy can&#8217;t it just be consistent?&#8221;\n<\/p>\n<p>\nNext time, why you also don&#8217;t see the pattern\n<code>typedef struct { ... } XYZ<\/code> very much either.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Windows header files, many structures are declared like this: typedef struct tagXYZ { &#8230; } XYZ; typedef struct _XYZ { &#8230; } XYZ; \/* there are other variations, too *\/ Why is the structure name different from typedef name? This is a holdover from very early versions of the C language where structure tags, [&hellip;]<\/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":[2],"class_list":["post-22993","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-history"],"acf":[],"blog_post_summary":"<p>In Windows header files, many structures are declared like this: typedef struct tagXYZ { &#8230; } XYZ; typedef struct _XYZ { &#8230; } XYZ; \/* there are other variations, too *\/ Why is the structure name different from typedef name? This is a holdover from very early versions of the C language where structure tags, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/22993","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=22993"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/22993\/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=22993"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=22993"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=22993"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}