{"id":22803,"date":"2008-04-09T10:00:00","date_gmt":"2008-04-09T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2008\/04\/09\/use-the-error-directive-to-check-whether-the-compiler-even-sees-you\/"},"modified":"2008-04-09T10:00:00","modified_gmt":"2008-04-09T10:00:00","slug":"use-the-error-directive-to-check-whether-the-compiler-even-sees-you","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20080409-00\/?p=22803","title":{"rendered":"Use the #error directive to check whether the compiler even sees you"},"content":{"rendered":"<p>\nYou may find yourself in a twisty maze of <code>#ifdef<\/code>s.\nOr you may be wondering why your macros aren&#8217;t working.\n<\/p>\n<blockquote CLASS=\"m\">\n<p>\nI have these lines in my header file:\n<\/p>\n<pre>\n#define MM_BUSY     0x0001\n#define MM_IDLE     0x0002\n<\/pre>\n<p>\nbut when I try to use them, I get errors.\n<\/p>\n<pre>\nsample.cpp(23): error C2065: 'MM_BUSY': undeclared identifier\nsample.cpp(40): error C2065: 'MM_IDLE': undeclared identifier\n<\/pre>\n<p>\nAny idea why this is happening?\n<\/p>\n<\/blockquote>\n<p>\nFirst, make sure the compiler even sees you.\nNotice that for macros, generating a preprocessed file\ndoesn&#8217;t accomplish anything since <code>#define<\/code>s don&#8217;t\nshow up in the preprocessor output.\n(They are preprocessor <i>input<\/i>.)\nWhat I do is use the <code>#error<\/code> directive.\nAdd it to the header file and recompile.\n<\/p>\n<pre>\n#define MM_BUSY     0x0001\n#define MM_IDLE     0x0002\n#error Did we get here?\n<\/pre>\n<p>\nIf you get\n<\/p>\n<pre>\nsample.h(80) : error C1189: #error :  Did we get here?\n<\/pre>\n<p>\nthen you know that the line is indeed being compiled\nand that somebody after you is doing an <code>#undef MM_BUSY<\/code>.\nIf not, then you get to investigate why the lines in the header\nfile are being ignored.\nFor example,\nthey might be hidden by an <code>#ifdef<\/code>,\nor (if you&#8217;re using Visual Studio with precompiled headers),\nyour <code>#include<\/code> directive might be ignored due to an\noverriding precompiled header directive.\nYou can scatter <code>#error<\/code> directives into other parts\nof the header file (or other header files) to narrow down why\nyour lines are being skipped.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You may find yourself in a twisty maze of #ifdefs. Or you may be wondering why your macros aren&#8217;t working. I have these lines in my header file: #define MM_BUSY 0x0001 #define MM_IDLE 0x0002 but when I try to use them, I get errors. sample.cpp(23): error C2065: &#8216;MM_BUSY&#8217;: undeclared identifier sample.cpp(40): error C2065: &#8216;MM_IDLE&#8217;: undeclared [&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":[25],"class_list":["post-22803","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>You may find yourself in a twisty maze of #ifdefs. Or you may be wondering why your macros aren&#8217;t working. I have these lines in my header file: #define MM_BUSY 0x0001 #define MM_IDLE 0x0002 but when I try to use them, I get errors. sample.cpp(23): error C2065: &#8216;MM_BUSY&#8217;: undeclared identifier sample.cpp(40): error C2065: &#8216;MM_IDLE&#8217;: undeclared [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/22803","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=22803"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/22803\/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=22803"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=22803"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=22803"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}