{"id":36923,"date":"2004-12-22T07:00:00","date_gmt":"2004-12-22T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2004\/12\/22\/bool-vs-variant_bool-vs-boolean-vs-bool\/"},"modified":"2004-12-22T07:00:00","modified_gmt":"2004-12-22T07:00:00","slug":"bool-vs-variant_bool-vs-boolean-vs-bool","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20041222-00\/?p=36923","title":{"rendered":"BOOL vs. VARIANT_BOOL vs. BOOLEAN vs. bool"},"content":{"rendered":"<p><P>\nStill more ways of saying the same thing.\nWhy so many?\n<\/P>\n<P>\nBecause each was invented by different people\nat different times to solve different problems.\n<\/P>\n<P>\n<CODE>BOOL<\/CODE> is the oldest one.  Its definition is simply\n<\/P>\n<PRE>\ntypedef int BOOL;\n<\/PRE>\n<P>\nThe C programming language uses &#8220;int&#8221; as its boolean type,\nand Windows&nbsp;1.0 was written back when C was the cool\nlanguage for systems programming.\n<\/P>\n<P>\nNext came <CODE>BOOLEAN<\/CODE>.\n<\/P>\n<PRE>\ntypedef BYTE  BOOLEAN;\n<\/PRE>\n<P>\nThis type was introduced by the\nOS\/2&nbsp;NT team when they decided to write a new\noperating system from scratch.  It lingers in Win32\nin the places where the original NT&nbsp;design peeks through,\nlike the security subsystem and interacting with drivers.\n<\/P>\n<P>\nOff to the side came <CODE>VARIANT_BOOL<\/CODE>.\n<\/P>\n<PRE>\ntypedef short VARIANT_BOOL;\n#define VARIANT_TRUE ((VARIANT_BOOL)-1)\n#define VARIANT_FALSE ((VARIANT_BOOL)0)\n<\/PRE>\n<P>\nThis was developed by the Visual Basic folks.\nBasic uses <CODE>-1<\/CODE> to represent &#8220;true&#8221;\nand <CODE>0<\/CODE> to represent &#8220;false&#8221;,\nand <CODE>VARIANT_BOOL<\/CODE> was designed to preserve this behavior.\n<\/P>\n<P>\n<STRONG>Common bug<\/STRONG>:  When manipulating <CODE>VARIANT<\/CODE>s\nof type <CODE>VT_BOOL<\/CODE>, and you want to set a boolean value to &#8220;true&#8221;,\nyou must use <CODE>VARIANT_TRUE<\/CODE>.\nMany people mistakenly use <CODE>TRUE<\/CODE> or <CODE>true<\/CODE>,\nwhich are not the same thing as <CODE>VARIANT_TRUE<\/CODE>.\nYou can cause problem with scripting languages if you get them confused.\n(For symmetry, you should also use <CODE>VARIANT_FALSE<\/CODE>\ninstead of <CODE>FALSE<\/CODE> or <CODE>false<\/CODE>.\nAll three have the same numerical value, however.\nConsequently, a mistake when manipulating &#8220;false&#8221; values is not fatal.)\n<\/P>\n<P>\nNewest on the scene is <CODE>bool<\/CODE>, which is a C++ data type\nthat has the value <CODE>true<\/CODE> or <CODE>false<\/CODE>.\nYou won&#8217;t see this used much (if at all) in Win32 because Win32 tries to\nremain C-compatible.\n<\/P>\n<P>\n(Note that C-compatible isn&#8217;t the same as C-friendly.\nAlthough you can do COM from C, it isn&#8217;t fun.)\n<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Still more ways of saying the same thing. Why so many? Because each was invented by different people at different times to solve different problems. BOOL is the oldest one. Its definition is simply typedef int BOOL; The C programming language uses &#8220;int&#8221; as its boolean type, and Windows&nbsp;1.0 was written back when C was [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-36923","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Still more ways of saying the same thing. Why so many? Because each was invented by different people at different times to solve different problems. BOOL is the oldest one. Its definition is simply typedef int BOOL; The C programming language uses &#8220;int&#8221; as its boolean type, and Windows&nbsp;1.0 was written back when C was [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/36923","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=36923"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/36923\/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=36923"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=36923"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=36923"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}