<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>[4.9.14] #define false 0 !?</title>
		<link>http://www.allegro.cc/forums/view/601957</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sun, 25 Oct 2009 02:09:08 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>astdbool.h does this:
</p><div class="source-code snippet"><div class="inner"><pre><span class="p"># define bool _Bool</span>
<span class="p"># define false 0</span>
<span class="p"># define true 1</span>
</pre></div></div><p>

This is <i>not</i> a good idea. It means using Allegro in C++ applications becomes hazardous to impossible, as it breaks overload resolution and template specialization involving bools; <i>false</i> and <i>true</i> are now ints rather than bools, which match differently (for instance, in MSVC9, the integer constant 0 matches pointers better [or at least <i>as</i> good as] than it matches bools, so a function overloaded on bool and char* will have the latter version chosen when you pass <i>true</i> or <i>false</i> to it).</p><p>Patch is simple; just wrap it in #ifndef __cplusplus so that these defines don&#39;t exist for C++ applications:
</p><div class="source-code snippet"><div class="inner"><pre><span class="p">#ifndef __cplusplus</span>
<span class="p"># define bool _Bool</span>
<span class="p"># define false 0</span>
<span class="p"># define true 1</span>
<span class="p">#endif</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Sat, 24 Oct 2009 18:44:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>There&#39;s also this comment above:
</p><div class="source-code snippet"><div class="inner"><pre><span class="c">/* This code is recommended by the autoconf manual */</span>
</pre></div></div><p>

Which almost implies it&#39;s a very bad idea... <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>And I wonder if we still support any compiler where stdbool.h doesn&#39;t exist anyway...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Sat, 24 Oct 2009 21:14:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, as mentioned, on MSVC9 at least the aforementioned defines got defined (the reason I&#39;m posting is of course because I got bit by this <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />), implying ALLEGRO_HAVE_STDBOOL_H was not defined...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Sat, 24 Oct 2009 21:17:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/601957/834584#target">Elias</a> said:</div><div class="quote"><p>
And I wonder if we still support any compiler where stdbool.h doesn&#39;t exist anyway...
</p></div></div><p>
MSVC 9 doesn&#39;t have stdbool.h. It&#39;s a C99 header and MSVC is&#39;nt a C99 compiler.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Oscar Giner)</author>
		<pubDate>Sat, 24 Oct 2009 22:25:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/601957/834585#target">X-G</a> said:</div><div class="quote"><p>
because I got bit by this
</p></div></div><p>
Ah that must have been nasty...</p><p>Got to love template errors.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ImLeftFooted)</author>
		<pubDate>Sun, 25 Oct 2009 01:25:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve changed it to this, so astdbool.h does nothing in C++. I don&#39;t see any reason to define _Bool in C++.</p><div class="source-code snippet"><div class="inner"><pre><span class="p">#ifndef __cplusplus</span>
<span class="p">#  ifdef ALLEGRO_HAVE_STDBOOL_H</span>
<span class="p">#     include &lt;stdbool.h&gt;</span>
<span class="p">#  else</span>
<span class="p">#     ifndef ALLEGRO_HAVE__BOOL</span>
         <span class="k1">typedef</span> <span class="k1">unsigned</span> <span class="k1">char</span> _Bool<span class="k2">;</span>
<span class="p">#     endif</span>
<span class="p">#     define bool _Bool</span>
<span class="p">#     define false 0</span>
<span class="p">#     define true 1</span>
<span class="p">#     define __bool_true_false_are_defined 1</span>
<span class="p">#  endif</span>
<span class="p">#endif</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Sun, 25 Oct 2009 02:09:08 +0000</pubDate>
	</item>
</rss>
