<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Will this code work?</title>
		<link>http://www.allegro.cc/forums/view/602399</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 09 Dec 2009 02:17:44 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="source-code snippet"><div class="inner"><pre><span class="p">#include &lt;stdio.h&gt;</span>

<span class="p">#define FATAL_ERROR {int* a=NULL; *a=1;}</span>

<span class="k1">int</span> main<span class="k2">(</span><span class="k1">int</span> argc, <span class="k1">char</span><span class="k3">*</span><span class="k3">*</span> argv<span class="k2">)</span><span class="k2">{</span>
    <span class="k1">if</span><span class="k2">(</span><span class="n">1</span><span class="k3">=</span><span class="k3">=</span><span class="n">0</span><span class="k2">)</span>
       FATAL_ERROR
    <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (type568)</author>
		<pubDate>Sat, 05 Dec 2009 00:44:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That specific code <i>might</i> work.</p><p>You really don&#39;t want to try and access invalid pointers like that. just use <span class="source-code"><a href="http://www.delorie.com/djgpp/doc/libc/libc_37.html" target="_blank">abort</a><span class="k2">(</span><span class="k2">)</span></span> or even <span class="source-code"><a href="http://www.delorie.com/djgpp/doc/libc/libc_298.html" target="_blank">exit</a><span class="k2">(</span><span class="k2">)</span></span> instead.</p><p>Also, theres an issue with the {}s. If you try and put it in certain places, you&#39;ll start to get confused.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Sat, 05 Dec 2009 00:58:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It was easier to open up the Allegro.cc forums to ask this rather than putting it into a compiler?</p><p>Define &quot;work&quot;.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (StevenVI)</author>
		<pubDate>Sat, 05 Dec 2009 00:58:46 +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/602399/840963#target">Thomas Fjellstrom</a> said:</div><div class="quote"><p>
Also, theres an issue with the {}s. If you try and put it in certain places, you&#39;ll start to get confused.
</p></div></div><p>

I edited the first post before your reply. Is it ok now?</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/602399/840964#target">StevenVI</a> said:</div><div class="quote"><p>
It was easier to open up the Allegro.cc forums to ask this rather than putting it into a compiler?
</p></div></div><p>

It compiles.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Define &quot;work&quot;.
</p></div></div><p>

No.</p><p>Append: That&#39;s not coz I don&#39;t want to.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (type568)</author>
		<pubDate>Sat, 05 Dec 2009 01:04:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>My initial thought was no...</p><p><span class="remote-thumbnail"><span class="json">{"name":"599918","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/7\/87aa5d17258a1186c51946c1ded42232.jpg","w":1024,"h":768,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/7\/87aa5d17258a1186c51946c1ded42232"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/8/7/87aa5d17258a1186c51946c1ded42232-240.jpg" alt="599918" width="240" height="180" /></span></p><p>EDIT-- ah, but now now I see this has to do with Matthew...<br /><a href="http://www.allegro.cc/forums/thread/602288">http://www.allegro.cc/forums/thread/602288</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Jeff Bernard)</author>
		<pubDate>Sat, 05 Dec 2009 01:11:10 +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/602399/840966#target">type568</a> said:</div><div class="quote"><p>I edited the first post before your reply. Is it ok now?</p></div></div><p>It looks the same to me <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><p>You generally don&#39;t want to put bare {}s in a define.</p><p>do something like: <span class="source-code"><span class="p">#define BLAH do{ codehere }while(0)</span></span> instead.</p><p>Then you can use it like so: <span class="source-code"><span class="k1">if</span><span class="k2">(</span>foo<span class="k2">)</span> BLAH<span class="k2">;</span></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Sat, 05 Dec 2009 01:42:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes.</p><p>And no, you don&#39;t want to do it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Billybob)</author>
		<pubDate>Sat, 05 Dec 2009 02:23:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hmmm, made me think, what if:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span> <span class="k2">(</span><span class="n">1</span> <span class="k3">=</span><span class="k3">=</span> <span class="n">0</span><span class="k2">)</span> <span class="k2">{</span>
<span class="k2">}</span>
</pre></div></div><p>

Actually returned <span class="source-code"><span class="k1">true</span></span>? What would that mean?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Vanneto)</author>
		<pubDate>Sat, 05 Dec 2009 02:24:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It will never return true because it&#39;s the same if &quot;a=1;b=0; if(a==b)&quot; would have returned true: nothing would have worked as expected.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (GullRaDriel)</author>
		<pubDate>Sat, 05 Dec 2009 02:36:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What if I were a millionaire? What would that mean?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Sat, 05 Dec 2009 02:40:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That you are still asleep and dreaming, BAF ;-)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (GullRaDriel)</author>
		<pubDate>Sat, 05 Dec 2009 02:41:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Sat, 05 Dec 2009 02:43:30 +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/602399/840983#target">Vanneto</a> said:</div><div class="quote"><p>
Actually returned true? What would that mean?
</p></div></div><p>

That would mean a <i>FATAL ERROR</i> I suppose..
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (type568)</author>
		<pubDate>Sat, 05 Dec 2009 02:43:39 +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/602399/840983#target">Vanneto</a> said:</div><div class="quote"><p>
Hmmm, made me think, what if:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span> <span class="k2">(</span><span class="n">1</span> <span class="k3">=</span><span class="k3">=</span> <span class="n">0</span><span class="k2">)</span> <span class="k2">{</span>
<span class="k2">}</span>
</pre></div></div><p>
Actually returned true? What would that mean?</p></div></div><p>

That would basically mean the compiler malfunctioned, and given such a compiler, god knows what FATAL_ERROR would do.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (anonymous)</author>
		<pubDate>Sat, 05 Dec 2009 05:54:28 +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/602399/840969#target">Thomas Fjellstrom</a> said:</div><div class="quote"><p>
You generally don&#39;t want to put bare {}s in a define.
</p></div></div><p>

I guess last question in this thread.. Thomas, is there a real reason not to put a {} in a define?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (type568)</author>
		<pubDate>Mon, 07 Dec 2009 09:51:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>No real one except it&#39;s unneeded.</p><p>They&#39;re needed in case of a if/do/while/for statement inside the #define, but you gain nothing adding {} in some simple statements as int *it; it=NULL, except huge problem spotting out the bug if you forgot to close/open a {}
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (GullRaDriel)</author>
		<pubDate>Mon, 07 Dec 2009 15:15:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve used similar code (writing at NULL) to test my signal handler.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Mon, 07 Dec 2009 15:45:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Audric: I use kill -signal for that kind of things.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (GullRaDriel)</author>
		<pubDate>Mon, 07 Dec 2009 18:22:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Actually, I DO need the {} in the define, as otherwise the above code won&#39;t even compile. As the macro is just replaced with it, and only one line is scoped in to an if statement(and the a won&#39;t be declared identifier).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (type568)</author>
		<pubDate>Mon, 07 Dec 2009 19:49:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You DO need it because of your implementation. </p><p>Keep in mind that #define are just preprocessing substitution.</p><p>Doing so would also work:
</p><div class="source-code snippet"><div class="inner"><pre><span class="p">#include &lt;stdio.h&gt;</span>

<span class="p">#define FATAL_ERROR int* a=NULL; *a=1 </span>

<span class="k1">int</span> main<span class="k2">(</span><span class="k1">int</span> argc, <span class="k1">char</span><span class="k3">*</span><span class="k3">*</span> argv<span class="k2">)</span><span class="k2">{</span>
    <span class="k1">if</span><span class="k2">(</span><span class="n">1</span><span class="k3">=</span><span class="k3">=</span><span class="n">0</span><span class="k2">)</span>
    <span class="k2">{</span>
        FATAL_ERROR<span class="k2">;</span>
    <span class="k2">}</span>
    <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

Plus your macro is evil. <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (GullRaDriel)</author>
		<pubDate>Mon, 07 Dec 2009 20:03:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That&#39;s what I meant.. But I wanna be referring to a single line MACRO as to a single line.. I still wonder what did Thomas mean though.</p><p>Append:
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/602399/841324#target">GullRaDriel</a> said:</div><div class="quote"><p>
Plus your macro is evil. 
</p></div></div><p>

Is my if statement less evil?<br />All this thread was sort of a joke.. Bit smelling with philosophy- as of what an actually working code is.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (type568)</author>
		<pubDate>Mon, 07 Dec 2009 20:41:13 +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/602399/841331#target">type568</a> said:</div><div class="quote"><p>I still wonder what did Thomas mean though.</p></div></div><p>Well for one, when you look at a bare macro do you always remember it has {}s surrounding it? What if you put it some place that causes a compiler error? Will you remember then that it is a block?</p><p>I already gave the proper alternative. a <span class="source-code"><span class="k1">do</span><span class="k2">{</span>CODE HERE<span class="k2">}</span><span class="k1">while</span><span class="k2">(</span><span class="n">0</span><span class="k2">)</span></span> construct. That way its a statement, and not a block. And can be used in any place a regular statement can be, without any problems.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Mon, 07 Dec 2009 21:16:41 +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/602399/841341#target">Thomas Fjellstrom</a> said:</div><div class="quote"><p>That way its a statement, and not a block.</p></div></div><p>
I have a feeling you are correct, but I am curious for an example as well. An example of where his implementation would cause an error, and yours would not.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Billybob)</author>
		<pubDate>Mon, 07 Dec 2009 22:46:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Example (google on &quot;define while 0&quot;):<br /><a href="http://stackoverflow.com/questions/923822/whats-the-use-of-do-while0-when-we-define-a-macro">http://stackoverflow.com/questions/923822/whats-the-use-of-do-while0-when-we-define-a-macro</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Tue, 08 Dec 2009 00:32:19 +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/602399/841341#target">Thomas Fjellstrom</a> said:</div><div class="quote"><p>
Well for one, when you look at a bare macro do you always remember it has {}s surrounding it? What if you put it some place that causes a compiler error? Will you remember then that it is a block?
</p></div></div><p>

That&#39;s it.. I can&#39;t imagine such a case. Unless I decided to do some assignment works out of scope of a function..</p><p>However, is not this:
</p><div class="source-code snippet"><div class="inner"><pre><span class="p">#define FATAL_ERROR {int* a=NULL; *a=1;};</span>
</pre></div></div><p>

Easier?</p><p> I didn&#39;t check this one, but I&#39;m quite sure that MSVC(latest one) at least won&#39;t give errors to that.. Furthermore, I encountered a ;; in my code, without any warnings, and of course without side effects as well. a ; is a ;, it doesn&#39;t harm if doubled, unless really misplaced.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (type568)</author>
		<pubDate>Tue, 08 Dec 2009 04:36:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>No, that&#39;s still not right. Check out the link Audric posted, but anyway, here&#39;s your example:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span><span class="k2">(</span>crash<span class="k2">)</span> FATAL_ERROR<span class="k2">;</span>
<span class="k1">else</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"okay"</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

Just using plain {}, that code would turn into:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span><span class="k2">(</span>crash<span class="k2">)</span> <span class="k2">{</span><span class="c">/*blah*/</span><span class="k2">}</span><span class="k2">;</span>
<span class="k1">else</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"okay"</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

... which obviously isn&#39;t right.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Tue, 08 Dec 2009 06:25:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>And if that would be</p><div class="source-code snippet"><div class="inner"><pre><span class="p">#define FATAL_ERROR exit();</span>
</pre></div></div><p>

It also wouldn&#39;t be right, due to the risk of having a:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span><span class="k2">(</span>crash<span class="k2">)</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_298.html" target="_blank">exit</a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span><span class="k2">;</span>
<span class="k1">else</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"okay"</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (type568)</author>
		<pubDate>Tue, 08 Dec 2009 06:28:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Don&#39;t put the ; in the define.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Tue, 08 Dec 2009 07:25:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you for the link to Stack Overflow, that explains everything.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Billybob)</author>
		<pubDate>Tue, 08 Dec 2009 13:00:06 +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/602399/840966#target">type568</a> said:</div><div class="quote"><p>
It compiles.
</p></div></div><p>
Doesn&#39;t mean sh* with macros.</p><div class="source-code snippet"><div class="inner"><pre><span class="p">#define foobar Hello there, you don't know me but I compile! Yay!@@#$%$QWQU</span>

<span class="k1">int</span> main<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span>
  <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tobias Dammers)</author>
		<pubDate>Tue, 08 Dec 2009 16:14:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>There is a difference between just defining a macro and actually using it. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Vanneto)</author>
		<pubDate>Tue, 08 Dec 2009 22:27:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, I did compile it and did put it in to the code(binary code was generated using the Macro) hence your notes seem to be irrelevant.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (type568)</author>
		<pubDate>Wed, 09 Dec 2009 01:31:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Okay, have fun then. It&#39;s not like I&#39;m going to have to deal with your messes... at least I hope not. I&#39;ll watch out for you on the daily wtf. <img src="http://www.allegro.cc/forums/smileys/cool.gif" alt="8-)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Wed, 09 Dec 2009 02:11:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (type568)</author>
		<pubDate>Wed, 09 Dec 2009 02:17:44 +0000</pubDate>
	</item>
</rss>
