{"id":22793,"date":"2008-04-10T10:00:00","date_gmt":"2008-04-10T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2008\/04\/10\/who-defined-my-name-first-turnabout-is-fair-play\/"},"modified":"2021-01-02T10:28:47","modified_gmt":"2021-01-02T18:28:47","slug":"20080410-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20080410-00\/?p=22793","title":{"rendered":"Who defined my name first? Turnabout is fair play"},"content":{"rendered":"<p>You&#8217;re trying to compile your program and you&#8217;re getting an error complaining that somebody already has a conflicting definition for a macro or some other name you&#8217;re using.<\/p>\n<pre>error: sample.cpp(35): conflicting definition of macro 'AWESOME'\r\nerror: sample.cpp(92): conflicting definition of type 'AWESOME'\r\n<\/pre>\n<p>If your compiler is helpful, it&#8217;ll tell you where the previous definition was. But what if your compiler isn&#8217;t quite so helpful? How can you find that conflicting definition?<\/p>\n<p>Turnabout is fair play.<\/p>\n<p>(I don&#8217;t actually believe that turnabout is fair play, but it makes for a catchy title.)<\/p>\n<p>The problem is that you&#8217;re the second definition and you want to find the first definition. So jump to the head of the line and become the new first definition. Compile the file with the <code>-DAWESOME=@<\/code> command line switch. This tells the compiler to act as if the line <code>#define AWESOME @<\/code> were at the top of the file.<\/p>\n<p>When the offending line is reached, the line that defines the <code>AWESOME<\/code> macro or declares a type named <code>AWESOME<\/code> or otherwise uses the word <code>AWESOME<\/code>, you&#8217;ll get a compiler error. If it&#8217;s a conflicting macro definition, you&#8217;ll get something like<\/p>\n<pre>error: header.h(10): conflicting definition of macro 'AWESOME'\r\n<\/pre>\n<p>when the first definition is reached. With your addition of the <code>-D<\/code>, it&#8217;s now the <i>second<\/i> definition, and therefore its definition conflicts with yours. Similarly, if it&#8217;s a conflicting type name, you&#8217;ll get something like<\/p>\n<pre>error: header.h(30): illegal character @ in source file\r\n<\/pre>\n<p>when the conflicting type definition is reached. This time, instead of a conflicting macro definition, you created a syntax error.<\/p>\n<p>On the other hand, if somebody <code>#undef<\/code>s your symbol before redefining it, then the <code>-D<\/code> trick won&#8217;t work.<\/p>\n<p>As I noted, if your compiler is friendly and helpful, you won&#8217;t need to use this tip, but sometimes you have to make do with what you&#8217;ve got.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Identifying who is creating the conflicting definition.<\/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":[25],"class_list":["post-22793","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Identifying who is creating the conflicting definition.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/22793","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=22793"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/22793\/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=22793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=22793"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=22793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}