<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Example I don&#39;t get</title>
		<link>http://www.allegro.cc/forums/view/590045</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 14 Feb 2007 00:42:13 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well it&#39;s not the examples themselves I don&#39;t get, but... <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" /> to the point;<br />I downloaded these Allegro examples and in each there is this thing I don&#39;t get.<br />It&#39;s (in the last line) used for initialization. Here&#39;s the part I don&#39;t get:
</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><span class="k1">int</span> depth_select<span class="k2">(</span><span class="k1">int</span> depth<span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">2</td><td>  <a href="http://www.allegro.cc/manual/set_color_depth" target="_blank"><span class="a">set_color_depth</span></a><span class="k2">(</span>depth<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">3</td><td>  <span class="k1">return</span> <span class="k3">!</span><a href="http://www.allegro.cc/manual/set_gfx_mode" target="_blank"><span class="a">set_gfx_mode</span></a><span class="k2">(</span>GFX_AUTODETECT, scr_width, scr_height, <span class="n">0</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">4</td><td><span class="k2">}</span></td></tr><tr><td class="number">5</td><td>&#160;</td></tr><tr><td class="number">6</td><td><span class="k1">void</span> init_all<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">7</td><td>  <a href="http://www.allegro.cc/manual/allegro_init" target="_blank"><span class="a">allegro_init</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">8</td><td>&#160;</td></tr><tr><td class="number">9</td><td>  <a href="http://www.allegro.cc/manual/install_keyboard" target="_blank"><span class="a">install_keyboard</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">10</td><td>  <a href="http://www.allegro.cc/manual/install_timer" target="_blank"><span class="a">install_timer</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">11</td><td>&#160;</td></tr><tr><td class="number">12</td><td>  <a href="http://www.allegro.cc/manual/LOCK_VARIABLE" target="_blank"><span class="a">LOCK_VARIABLE</span></a><span class="k2">(</span>elapsed_time<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">13</td><td>  <a href="http://www.allegro.cc/manual/LOCK_FUNCTION" target="_blank"><span class="a">LOCK_FUNCTION</span></a><span class="k2">(</span>__inc_elapsed_time<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">14</td><td>  <a href="http://www.allegro.cc/manual/install_int_ex" target="_blank"><span class="a">install_int_ex</span></a><span class="k2">(</span>__inc_elapsed_time, BPS_TO_TIMER<span class="k2">(</span><span class="n">1000</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">15</td><td>&#160;</td></tr><tr><td class="number">16</td><td>  depth_select<span class="k2">(</span><span class="n">32</span><span class="k2">)</span> <span class="k3">|</span><span class="k3">|</span> depth_select<span class="k2">(</span><span class="n">24</span><span class="k2">)</span> <span class="k3">|</span><span class="k3">|</span> depth_select<span class="k2">(</span><span class="n">16</span><span class="k2">)</span> <span class="k3">|</span><span class="k3">|</span> depth_select<span class="k2">(</span><span class="n">15</span><span class="k2">)</span><span class="k2">;</span><span class="c">//??</span></td></tr><tr><td class="number">17</td><td><span class="k2">}</span></td></tr></tbody></table></div></div><p>
Now, I&#39;m probably not being too bright, but what is that last line? I know about set_color_depth, but this seems weird. I mean &quot;||&quot;, what does this do?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (weapon_S)</author>
		<pubDate>Tue, 13 Feb 2007 16:18:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I mean &quot;||&quot;, what does this do?
</p></div></div><p>
... that&#39;s an OR. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (gnolam)</author>
		<pubDate>Tue, 13 Feb 2007 16:22:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hilarious... T_T<br />I know it&#39;s probably a stupid question, because it is such a basic operator, but I would appreciate a serious answer. Really I would.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (weapon_S)</author>
		<pubDate>Tue, 13 Feb 2007 16:27:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Tried using google?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Ceagon Xylas)</author>
		<pubDate>Tue, 13 Feb 2007 16:29:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Now, I&#39;m probably not being too bright, but what is that last line? I know about set_color_depth, but this seems weird. I mean &quot;||&quot;, what does this do?
</p></div></div><p>
A feature of short-circuit logic. If the first operand evaluates to TRUE, the second operand is not evaluated at all (since its value is not important for wether the end result is TRUE or FALSE).<br />This &quot;trick&quot; is common in shellscripts or Perl code (eg, open FILE, &quot;&lt;file&quot; || die &quot;file not found&quot;; ), but I&#39;ve never seen it used in C code. I&#39;m also not sure if the C standard guarentees the order of evaluation to be left to right.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Tue, 13 Feb 2007 16:31:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I&#39;m also not sure if the C standard guarentees the order of evaluation to be left to right.
</p></div></div><p>

For this, yes.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Tue, 13 Feb 2007 16:38:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It was a serious answer.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (gnolam)</author>
		<pubDate>Tue, 13 Feb 2007 16:42:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Tried using google?
</p></div></div><p>
How does one use google to find what || means?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (miran)</author>
		<pubDate>Tue, 13 Feb 2007 16:45:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What it does: If the first fails (i.e. evaluates to false) then the second is evaluated, if that fails then the third is evaluated etc. </p><p>Would be equivalent to 
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span><span class="k2">(</span><span class="k3">!</span>depth_select<span class="k2">(</span><span class="n">32</span><span class="k2">)</span><span class="k2">)</span>
  <span class="k1">if</span><span class="k2">(</span><span class="k3">!</span>depth_select<span class="k2">(</span><span class="n">24</span><span class="k2">)</span><span class="k2">)</span>
    <span class="k1">if</span><span class="k2">(</span><span class="k3">!</span>depth_select<span class="k2">(</span><span class="n">16</span><span class="k2">)</span><span class="k2">)</span>
      depth_select<span class="k2">(</span><span class="n">15</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tobing)</author>
		<pubDate>Tue, 13 Feb 2007 17:18:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">miran said:</div><div class="quote"><p>

[quote Ceagon Xylas]Tried using google?
</p></div></div><p>
How does one use google to find what || means?<br />&lt;/quote&gt;I was wondering the same thing. Actually, I thought the google comment was rude and unhelpful. It&#39;s like just posting &quot;I&#39;m not going to help you, work it out yourself - idiot.&quot;<br />If you don&#39;t want to help, just don&#39;t help. There is no need to <i>announce</i> that you aren&#39;t going to help.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Karadoc ~~)</author>
		<pubDate>Tue, 13 Feb 2007 17:35:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ah, yes, thanks.<br />( <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" /> I figured it out when I was off-line; amazing how just posting a question makes you think...) Does anyone know whether this works for sure? I.e. there&#39;s no compiler which scrambles the order for optimization?<br />And I don&#39;t do shellscripts... so that&#39;s probably why...<br />Now I need help understanding the Exlights example <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /><br />Maybe another day...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (weapon_S)</author>
		<pubDate>Tue, 13 Feb 2007 18:52:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I.e. there&#39;s no compiler which scrambles the order for optimization?
</p></div></div><p>
If they do, they&#39;re broken. Left-to-right order and minimal evaluation is guaranteed by the standard.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (gnolam)</author>
		<pubDate>Tue, 13 Feb 2007 19:03:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What gnolam says.<br />It allows expressions like :
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span> <span class="k2">(</span>bmp <span class="k3">!</span><span class="k3">=</span> NULL <span class="k3">&amp;</span><span class="k3">&amp;</span> bmp-&gt;width <span class="k3">&gt;</span> SCR_WIDTH<span class="k2">)</span> <span class="k2">{</span><span class="c">/*do stuff*/</span><span class="k2">}</span>
</pre></div></div><p>
The second term would horribly break if it was evaluated before of the first - or when the first was already known to be false.</p><p>edit: For the record, AFAIK, the only non-determined order of evaluation is functions arguments:
</p><div class="source-code snippet"><div class="inner"><pre>i<span class="k3">=</span><span class="n">0</span><span class="k2">;</span>
<a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a> <span class="k2">(</span><span class="s">"%d %d\n"</span>, i<span class="k3">+</span><span class="k3">+</span>, i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
It could print &quot;1 2&quot; or &quot;2 1&quot;.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Tue, 13 Feb 2007 22:11:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>For the record, I wouldn&#39;t consider doing that in a C program to be good coding style...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Tue, 13 Feb 2007 22:22:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Putting &quot;||&quot; into Google shows nothing. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kikaru)</author>
		<pubDate>Tue, 13 Feb 2007 22:50:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Or you could use your head and search for <i>C Operator &quot;or&quot;</i>.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Tue, 13 Feb 2007 22:53:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This is how it looks like<br /><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/2/5/2597232bb34d73119fc1d1102250b8ae.png" alt="150px-ORGate.png" width="150" height="117" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Paul whoknows)</author>
		<pubDate>Tue, 13 Feb 2007 23:11:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, wasn&#39;t trying to be rude, but I googled &#39;C++ operator&#39; As you would expect, it came up with a list of operators including ||, the or operator... This page also proceeded to explain <b>what</b> that operator does.</p><div class="quote_container"><div class="title">weapon_S said:</div><div class="quote"><p>
I know it&#39;s probably a stupid question, because it is such a basic operator
</p></div></div><p>
He apparently knew what operators were.</p><div class="quote_container"><div class="title">Karadoc ~~ said:</div><div class="quote"><p>
If you don&#39;t want to help, just don&#39;t help. There is no need to announce that you aren&#39;t going to help.
</p></div></div><p>
I guess my help was: I found it by this simple method which I&#39;ll now remind you to use. It discourages having it handed to you.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Ceagon Xylas)</author>
		<pubDate>Tue, 13 Feb 2007 23:56:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Don&#39;t ever adapt that coding style. It is just stupid, even though it looks neat. Depend more on your compiler&#39;s ability to optimize your nested ifs. IIRC there&#39;s a compiler option that makes <i>all</i> comparisons evaluated in a line like that. If you ever need to set that option for any reason, you don&#39;t want your program to run in wrong colour depth.</p><p>I avoid the following, too:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span> <span class="k2">(</span>b <span class="k3">=</span><span class="k3">=</span> <span class="n">0</span> <span class="k3">|</span><span class="k3">|</span> a <span class="k3">/</span> b <span class="k3">&gt;</span> foo<span class="k2">)</span> 
    bar<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

Instead:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span> <span class="k2">(</span>b <span class="k3">=</span><span class="k3">=</span> <span class="n">0</span><span class="k2">)</span>
    bar<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="k1">else</span>
    <span class="k1">if</span> <span class="k2">(</span>a <span class="k3">/</span> b <span class="k3">&gt;</span> foo<span class="k2">)</span> 
        bar<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

For same reason. </p><p>[edit]
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Well, wasn&#39;t trying to be rude, but I googled &#39;C++ operator&#39;
</p></div></div><p>
I remember when I first saw || in the code (might have been just |), ages ago. Even though I knew some C and had coded simple games, I just didn&#39;t recognise that it was an operator. I hardly knew the word &#39;operator&#39;. OTOH there was no Google at that time.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Johan Halmén)</author>
		<pubDate>Wed, 14 Feb 2007 00:12:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
<a href="http://thedailywtf.com/Articles/Turn_it_up_to_Eleven.aspx">*cough*</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Wed, 14 Feb 2007 00:42:13 +0000</pubDate>
	</item>
</rss>
