{"id":90831,"date":"2015-07-24T07:00:00","date_gmt":"2015-07-24T21:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20150724-00\/?p=90831\/"},"modified":"2019-03-13T12:17:41","modified_gmt":"2019-03-13T19:17:41","slug":"20150724-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20150724-00\/?p=90831","title":{"rendered":"The curse of the redefinition of the symbol HLOG"},"content":{"rendered":"<p>A customer was running into a compiler error complaining about redefinition of the symbol <code>HLOG<\/code>. <\/p>\n<pre>\n#include &lt;pdh.h&gt;\n#include &lt;lm.h&gt;\n\n...\n<\/pre>\n<p>The result is <\/p>\n<pre>\nlmerrlog.h(80): error C2373: 'HLOG' redefinition; different type modifiers\npdh.h(70): See declaration of 'HLOG'\n<\/pre>\n<p>&#8220;Our project uses both performance counters (<code>pdh.h<\/code>) and networking (<code>lm.h<\/code>). What can we do to avoid this conflict?&#8221; <\/p>\n<p><a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2008\/11\/07\/9051091.aspx\">We&#8217;ve seen this before<\/a>. The conflict arises from two problems. <\/p>\n<p>First is hubris\/lack of creativity. &#8220;My component does logging. I need a handle to a log. I will call it <code>HLOG<\/code> because (1) I can&#8217;t think of a better name, and\/or (2) obviously I&#8217;m the only person who does logging. (Anybody else who wants to do logging should just quit their job now because it&#8217;s been done.)&#8221; <\/p>\n<p>This wouldn&#8217;t normally be a problem except that Win32 uses a global namespace. This is necessary for annoying reasons: <\/p>\n<ul>\n<li>Not all Win32 languages support namespaces. \n<li>Even though C++ supports namespaces,     different C++ implementations decorate differently,     so there is no agreement on the external linkage.     (Indeed, the decoration can change from one version of the C++     compiler to another!) <\/ul>\n<p>Fortunately, in the case of <code>HLOG<\/code>, the two teams noticed the collision and came to some sort of understanding. If you include them in the order <\/p>\n<pre>\n#include &lt;lm.h&gt;\n#include &lt;pdh.h&gt;\n<\/pre>\n<p>then <code>pdh.h<\/code> detects that <code>lm.h<\/code> has already been included and avoids the conflicting definition. <\/p>\n<pre>\n#ifndef _LMHLOGDEFINED_\ntypedef PDH_HLOG     HLOG;\n#endif\n<\/pre>\n<p>The PDH log is always accessible via the name <code>PDH_HLOG<\/code>. If <code>lm.h<\/code> was not also included, then the PDH log is also accessible under the name <code>HLOG<\/code>. <\/p>\n<p>Sorry for the confusion. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Too generic a name.<\/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-90831","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Too generic a name.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/90831","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=90831"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/90831\/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=90831"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=90831"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=90831"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}