<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>need help with declaring a 2d int array</title>
		<link>http://www.allegro.cc/forums/view/391956</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sat, 07 Aug 2004 09:54:08 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>hi all,</p><p> i&#39;m miffed as to why this doesn&#39;t work. i get about 20 compile errors<br />when i compile, which aren&#39;t helping.</p><p> i think you should be able to see what i&#39;m trying to do but can you help me with how to do it properly ?</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td>&#160;</td></tr><tr><td class="number">2</td><td><span class="p">#define LARGEST_SHADING_CIRCLE_DIAMETER 520</span></td></tr><tr><td class="number">3</td><td><span class="p">#define SMALLEST_SHADING_CIRCLE_DIAMETER 192</span></td></tr><tr><td class="number">4</td><td><span class="p">#define DIAMETER_DECREMENT =\</span></td></tr><tr><td class="number">5</td><td><span class="p">        (LARGEST_SHADING_CIRCLE_DIAMETER - SMALLEST_SHADING_CIRCLE_DIAMETER)\ </span></td></tr><tr><td class="number">6</td><td><span class="p">        /10 </span></td></tr><tr><td class="number">7</td><td>&#160;</td></tr><tr><td class="number">8</td><td><span class="k1">int</span> circle_sizes<span class="k2">[</span><span class="n">10</span><span class="k2">]</span> <span class="k3">=</span> <span class="k2">{</span></td></tr><tr><td class="number">9</td><td>   LARGEST_SHADING_CIRCLE_DIAMETER,</td></tr><tr><td class="number">10</td><td>   LARGEST_SHADING_CIRCLE_DIAMETER <span class="k3">-</span> <span class="k2">(</span><span class="n">1</span> <span class="k3">*</span> DIAMETER_DECREMENT<span class="k2">)</span>,</td></tr><tr><td class="number">11</td><td>   LARGEST_SHADING_CIRCLE_DIAMETER <span class="k3">-</span> <span class="k2">(</span><span class="n">2</span> <span class="k3">*</span> DIAMETER_DECREMENT<span class="k2">)</span>,</td></tr><tr><td class="number">12</td><td>   LARGEST_SHADING_CIRCLE_DIAMETER <span class="k3">-</span> <span class="k2">(</span><span class="n">3</span> <span class="k3">*</span> DIAMETER_DECREMENT<span class="k2">)</span>,</td></tr><tr><td class="number">13</td><td>   LARGEST_SHADING_CIRCLE_DIAMETER <span class="k3">-</span> <span class="k2">(</span><span class="n">4</span> <span class="k3">*</span> DIAMETER_DECREMENT<span class="k2">)</span>,</td></tr><tr><td class="number">14</td><td>   LARGEST_SHADING_CIRCLE_DIAMETER <span class="k3">-</span> <span class="k2">(</span><span class="n">5</span> <span class="k3">*</span> DIAMETER_DECREMENT<span class="k2">)</span>,</td></tr><tr><td class="number">15</td><td>   LARGEST_SHADING_CIRCLE_DIAMETER <span class="k3">-</span> <span class="k2">(</span><span class="n">6</span> <span class="k3">*</span> DIAMETER_DECREMENT<span class="k2">)</span>,</td></tr><tr><td class="number">16</td><td>   LARGEST_SHADING_CIRCLE_DIAMETER <span class="k3">-</span> <span class="k2">(</span><span class="n">7</span> <span class="k3">*</span> DIAMETER_DECREMENT<span class="k2">)</span>,</td></tr><tr><td class="number">17</td><td>   LARGEST_SHADING_CIRCLE_DIAMETER <span class="k3">-</span> <span class="k2">(</span><span class="n">8</span> <span class="k3">*</span> DIAMETER_DECREMENT<span class="k2">)</span>,</td></tr><tr><td class="number">18</td><td>   SMALLEST_SHADING_CIRCLE_DIAMETER</td></tr><tr><td class="number">19</td><td><span class="k2">}</span><span class="k2">;</span></td></tr></tbody></table></div></div><p>

compile errors available if wanted.</p><p><img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Fri, 06 Aug 2004 20:07:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>compile errors available if wanted.</p></div></div><p>

Duh. <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" /></p><p>I&#39;m guessing wildly here, that the compiler doesn&#39;t like the ides of you initially constructing the array with values that have to be calculated or something? I have no idea, really. <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /></p><p>Your DIAMETER_DECREMENT declaration looks a bit suspect. I really do hate macros ...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Fri, 06 Aug 2004 20:08:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="source-code snippet"><div class="inner"><pre><span class="k1">int</span> circle_sizes<span class="k2">[</span><span class="n">10</span><span class="k2">]</span> <span class="k3">=</span> <span class="k2">{</span>
   LARGEST_SHADING_CIRCLE_DIAMETER,
</pre></div></div><p>

That happens at compiling time and the compiler doesn&#39;t calculate stuff like:
</p><div class="source-code snippet"><div class="inner"><pre>LARGEST_SHADING_CIRCLE_DIAMETER <span class="k3">-</span> <span class="k2">(</span><span class="n">1</span> <span class="k3">*</span> DIAMETER_DECREMENT<span class="k2">)</span>,
</pre></div></div><p>

or does it?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Johan Halmén)</author>
		<pubDate>Fri, 06 Aug 2004 20:11:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Lose the &#39;<b>=</b>&#39; in the third macro.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Rash)</author>
		<pubDate>Fri, 06 Aug 2004 20:12:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>yeah that&#39;s probably it i guess.</p><p>can&#39;t see why a compiler can&#39;t add a few ints together tho&#39;</p><p>it&#39;s nicer for me because this way facilitates easily trying different values.</p><p>i&#39;ll swap the sc&#39;s for numbers and see if it&#39;s more digestable</p><p><img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>

Lose the &#39;=&#39; in the third macro.</p></div></div><p>

will do <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>noone mentioned it being wrong earlier when i posted that<br />code on &#39;simple C question&#39; thread.</p><p>(i shouldn&#39;t use your brains as my compiler i suppose  <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />)</p><p>i thought the &#39;=&#39; was out of place (no other defines need one)</p><p>hope it works..
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Fri, 06 Aug 2004 20:13:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>can&#39;t see why a compiler can&#39;t add a few ints together tho&#39;</p></div></div><p>

Can&#39;t see why you can&#39;t declare your macro properly (and really, the only way to properly define a macro is to use something else. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />)</p><p>All three could be const int&#39;s, since the third macro only gets calculated once and doesn&#39;t change anyway ...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Fri, 06 Aug 2004 20:14:39 +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 guessing wildly here, that the compiler doesn&#39;t like the ides of you initially constructing the array with values that have to be calculated or something?
</p></div></div><p>
Since the resulting value can be arrived at at compile-time, where&#39;s the problem?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Rash)</author>
		<pubDate>Fri, 06 Aug 2004 20:18:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>How much <i>can</i> a compiler calculate? I&#39;ve never used anything else than constants in that kind of code lines.</p><p>[OT] Cheer up, Marvin:<br />http://edu.loviisa.fi/~jhalmen/images/marvin.jpg<br />That&#39;s better
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Johan Halmén)</author>
		<pubDate>Fri, 06 Aug 2004 20:24:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
Any compiler worth its salt will optimize constant operations together into a single constant when compiling. So if you type &quot;640 - 43&quot; in code, it won&#39;t actually do a subtraction whenever that&#39;s used; the compiler will just put the constant 596 in the program instead.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Fri, 06 Aug 2004 20:26:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you want a taste of what is possible, do a search for &quot;template metaprogramming&quot;.</p><p>[EDIT]
</p><div class="quote_container"><div class="title">X-G said:</div><div class="quote"><p>
Any compiler worth its salt will optimize constant operations together into a single constant when compiling. So if you type &quot;640 - 43&quot; in code, it won&#39;t actually do a subtraction whenever that&#39;s used; the compiler will just put the constant 596 in the program instead.
</p></div></div><p>
Thank you, Captain Obvious. Why do you think only computations involving constant values are allowed in standard code?<br />[/EDIT]
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Rash)</author>
		<pubDate>Fri, 06 Aug 2004 20:26:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Since the resulting value can be arrived at at compile-time, where&#39;s the problem?</p></div></div><p>

I didn&#39;t see one; that&#39;s why it was a wild guess. <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" /> I saw the &#39;=&#39; later.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Fri, 06 Aug 2004 20:31:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
Rash: The pseudo-Finn asked, so I answered. <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Fri, 06 Aug 2004 20:33:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="source-code snippet"><div class="inner"><pre><span class="p">#define LARGEST_SHADING_CIRCLE_DIAMETER 520</span>
<span class="p">#define SMALLEST_SHADING_CIRCLE_DIAMETER 192</span>
<span class="p">#define DIAMETER_INCREMENT ((LARGEST_SHADING_CIRCLE_DIAMETER - SMALLEST_SHADING_CIRCLE_DIAMETER) / 10)</span>

<span class="p">#define CIRCLE_SIZE(a) (SMALLEST_SHADING_CIRCLE_DIAMETER + a * DIAMETER_INCREMENT )</span>
</pre></div></div><p>
This should work ok. Note that I got CIRCLE_SIZE() backwards, but I found that more readable (0 is smallest, 10 biggest)</p><p>edit: what, macros are bad?<br />Good, bad, I&#39;m the guy with the gnu.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Yves Rizoud)</author>
		<pubDate>Fri, 06 Aug 2004 20:43:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You know, this thread perfectly shows why macros are pure evil. Make a mistake in declaring one, see the mistake somewhere else.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Rash)</author>
		<pubDate>Fri, 06 Aug 2004 20:43:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Make a mistake in declaring one, see the mistake somewhere else.</p></div></div><p>

That is so very annoying. <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /></p><p>Here&#39;s the only cool use of macros:</p><div class="source-code snippet"><div class="inner"><pre>   <span class="c">// arthurmath.cpp</span>
   <span class="p">#include &lt;iostream&gt;</span>
   <span class="p">#define SIX  1 + 5</span>
   <span class="p">#define NINE 8 + 1</span>

   <span class="k1">int</span> main<span class="k2">(</span><span class="k2">)</span>
   <span class="k2">{</span>
      std::cout <span class="k3">&lt;</span><span class="k3">&lt;</span> SIX <span class="k3">*</span> NINE <span class="k3">&lt;</span><span class="k3">&lt;</span> std::endl<span class="k2">;</span>
   <span class="k2">}</span>
</pre></div></div><p>
<img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Fri, 06 Aug 2004 20:47:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hey, I may have a roundoff error, but I <b>did</b> surround my numerical expressions with braces.</p><p>make it
</p><div class="source-code snippet"><div class="inner"><pre><span class="p">#define MAX_RADIUS 520</span>
<span class="p">#define MIN_RADIUS 192</span>
<span class="p">#define CIRCLES    10</span>

<span class="p">#define CIRCLE(a) ( (MAX_RADIUS - MIN_RADIUS) * (a) / CIRCLES + MIN_RADIUS  )</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Yves Rizoud)</author>
		<pubDate>Fri, 06 Aug 2004 20:56:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Macros are evil.  Use const for variables, inline functions for functions.  Macros are evil.  <b>Macros are evil.</b>  <i>evil</i>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (gillius)</author>
		<pubDate>Sat, 07 Aug 2004 01:56:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Geez. Since when are macros evil?<br />You just have to know when to use them.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (spellcaster)</author>
		<pubDate>Sat, 07 Aug 2004 02:01:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes, I agree with gillius. Even if you bypass the const protection, the code at runtime will crash.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ReyBrujo)</author>
		<pubDate>Sat, 07 Aug 2004 02:19:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>You just have to know when to use them.</p></div></div><p>

Which is not oftern. 19 times out of 20, there&#39;s a better way to accomplish what you&#39;re doing. I don&#39;t use macros unless I can&#39;t find some other safer/faster/easier option ... and I usually can ...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Sat, 07 Aug 2004 02:48:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>As long as there&#39;s no way to replace the # and ## macro operations, there&#39;s a need for defines. It&#39;s that easy.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (spellcaster)</author>
		<pubDate>Sat, 07 Aug 2004 02:52:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
Not familiar with what you mean. And bluntly, it&#39;s definitely not relevant to the code in the original post. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Sat, 07 Aug 2004 02:54:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I never said macros are useless.  I also never said they should never be used.  They are just evil.  All preprocessor stuff is evil, including the header guards.  An evil can be a necessary evil.  Now, in this case, I think he should be using const variables and not defines.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (gillius)</author>
		<pubDate>Sat, 07 Aug 2004 02:54:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>OT: 23, # is the stringtificator(sp?) operator, converting the parameter of a macro into a string, while ## is the concatenator, in case you didn&#39;t know <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ReyBrujo)</author>
		<pubDate>Sat, 07 Aug 2004 03:03:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
How often do you use MIN, MID and MAX? I find them very useful. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Richard Phipps)</author>
		<pubDate>Sat, 07 Aug 2004 03:27:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>All preprocessor stuff is evil, including the header guards.</p></div></div><p>
Why is that?</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Not familiar with what you mean</p></div></div><p>
The # operator puts it&#39;s operand in quotes.</p><div class="source-code snippet"><div class="inner"><pre><span class="p">#define DEBUG_CASE(value) case value: log(#value)</span>

<span class="k1">enum</span> <span class="k2">{</span>
   ERROR_SOMETHING
<span class="k2">}</span><span class="k2">;</span>

<span class="k1">switch</span> <span class="k2">(</span>returnCode<span class="k2">)</span> <span class="k2">{</span>
    DEBUG_CASE<span class="k2">(</span> ERROR_SOMETHING <span class="k2">)</span>
         <span class="c">// your code here</span>
    <span class="k1">break</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
will evalute into:
</p><div class="source-code snippet"><div class="inner"><pre>

<span class="k1">enum</span> <span class="k2">{</span>
   ERROR_SOMETHING
<span class="k2">}</span><span class="k2">;</span>

<span class="k1">switch</span> <span class="k2">(</span>returnCode<span class="k2">)</span> <span class="k2">{</span>
    <span class="k1">case</span> ERROR_SOMETHING:
         <a href="http://www.delorie.com/djgpp/doc/libc/libc_542.html" target="_blank">log</a><span class="k2">(</span><span class="s">"ERROR_SOMETHING"</span><span class="k2">)</span><span class="k2">;</span>
         <span class="c">// your code here</span>
    <span class="k1">break</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

You can also use it to create string representations for your constants:</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="c">// events.h</span></td></tr><tr><td class="number">2</td><td>EVENT<span class="k2">(</span> MSG_PlayerHit <span class="k2">)</span></td></tr><tr><td class="number">3</td><td>EVENT<span class="k2">(</span> MSG_EnemySpawned <span class="k2">)</span></td></tr><tr><td class="number">4</td><td>&#160;</td></tr><tr><td class="number">5</td><td><span class="c">// events.cpp</span></td></tr><tr><td class="number">6</td><td><span class="p">#define EVENT(msg) msg,</span></td></tr><tr><td class="number">7</td><td><span class="k1">enum</span> Events <span class="k2">{</span></td></tr><tr><td class="number">8</td><td>    <span class="p">#include "events.h"</span></td></tr><tr><td class="number">9</td><td><span class="k2">}</span><span class="k2">;</span></td></tr><tr><td class="number">10</td><td><span class="p">#undef EVENT</span></td></tr><tr><td class="number">11</td><td><span class="p">#define EVENT(msg) #x,</span></td></tr><tr><td class="number">12</td><td>&#160;</td></tr><tr><td class="number">13</td><td><span class="k1">static</span> <span class="k1">const</span> <span class="k1">char</span><span class="k3">*</span> EventStrings<span class="k2">[</span><span class="k2">]</span> <span class="k3">=</span> <span class="k2">{</span></td></tr><tr><td class="number">14</td><td>     <span class="p">#include "events.h"</span></td></tr><tr><td class="number">15</td><td><span class="k2">}</span><span class="k2">;</span></td></tr><tr><td class="number">16</td><td><span class="p">#undef EVENT</span></td></tr></tbody></table></div></div><p>

You can also use it if you&#39;re too lazy to write your own embedded language parser. I used the preprocessor to create a little &quot;embedded language&quot; so createing the JS interface is more easy.<br />I could have written something like luaBind, but why should I? The cpp is tried and proven and works perfectly well <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>So, code like this:</p><div class="source-code snippet"><div class="inner"><pre>
GetterStart
    GetterAttributesStart

        Get<span class="k2">(</span> width <span class="k2">)</span>
            <span class="c">// return width as JS var</span>
     
        Get<span class="k2">(</span> height <span class="k2">)</span>
           <span class="c">// return height as JS var</span>
       
    GetterAttributesEnd
GetterEnd
</pre></div></div><p>

Is translated into the correct interface calls:
</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td>JSBool gimlJSImageGetFunc<span class="k2">(</span>JSContext <span class="k3">*</span>jsContext, JSObject <span class="k3">*</span>thisObj, jsval id, jsval <span class="k3">*</span>vp<span class="k2">)</span> <span class="k2">{</span> </td></tr><tr><td class="number">2</td><td>    JSBool result <span class="k3">=</span> JS_TRUE<span class="k2">;</span></td></tr><tr><td class="number">3</td><td>&#160;</td></tr><tr><td class="number">4</td><td>    <span class="k1">if</span> <span class="k2">(</span>JSVAL_IS_INT<span class="k2">(</span>id<span class="k2">)</span><span class="k2">)</span>  <span class="k2">{</span> </td></tr><tr><td class="number">5</td><td>          <span class="k1">switch</span><span class="k2">(</span>JSVAL_TO_INT<span class="k2">(</span>id<span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span> </td></tr><tr><td class="number">6</td><td>               <span class="k1">case</span> <span class="n">0xEfffffff</span><span class="k2">:</span> <span class="k2">{</span></td></tr><tr><td class="number">7</td><td>               <span class="k2">}</span></td></tr><tr><td class="number">8</td><td>               <span class="k1">case</span> GIML_JS_IMG_WIDTH: <span class="k2">{</span></td></tr><tr><td class="number">9</td><td>                    <span class="c">// return width as JS var</span></td></tr><tr><td class="number">10</td><td>               <span class="k2">}</span> <span class="k1">break</span><span class="k2">;</span></td></tr><tr><td class="number">11</td><td>               <span class="k1">case</span> GIML_JS_IMG_HEIGHT: <span class="k2">{</span></td></tr><tr><td class="number">12</td><td>                    <span class="c">// return height as JS var</span></td></tr><tr><td class="number">13</td><td>               <span class="k2">}</span> <span class="k1">break</span><span class="k2">;</span></td></tr><tr><td class="number">14</td><td>          <span class="k2">}</span></td></tr><tr><td class="number">15</td><td>     <span class="k2">}</span></td></tr><tr><td class="number">16</td><td><span class="k2">}</span></td></tr></tbody></table></div></div><p>
The Image and IMG parts are of course dynamic <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>So I didn&#39;t had to write a special parser. And writing interface code got more readable.<br />I got that idea from an artcile in Game Programming GemsI, where a complete state machine was developed that way. You should check it out, the resulting code is quite neat.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (spellcaster)</author>
		<pubDate>Sat, 07 Aug 2004 03:32:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>I got that idea from an artcile in Game Programming GemsI, where a complete state machine was developed that way. You should check it out, the resulting code is quite neat.</p></div></div><p>

Not sure I curently have need for such a thing, but it&#39;s not like I can afford any of the GPG books anyway. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Sat, 07 Aug 2004 03:37:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>spellcaster, it is useful, but when you create complex macros like in MFC, you are abusing the language features <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> Especially if you add bunch of code in a macro.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ReyBrujo)</author>
		<pubDate>Sat, 07 Aug 2004 04:09:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>spellcaster, it is useful, but when you create complex macros like in MFC, you are abusing the language features</p></div></div><p>
If it saves me several days of coding and testing, is more easy to read and doesn&#39;t require any new utilities, it&#39;s not abuse.<br />Esp. not since the preprocessor was made to do that job. I&#39;m not abusing it, I&#39;m using it.</p><p>I agree that inline functions and constants / enums should be used where it is possible. But if you want to output a linenumber, you should better use the <u>_LINE</u>_ macro <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>Know your tools, and use them well. That includes cpp.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (spellcaster)</author>
		<pubDate>Sat, 07 Aug 2004 04:12:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Sure, but having something like this is evil:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">int</span> main<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span>
    INITIALIZE_ALLEGRO<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
    PLAY_GAME<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
    TERMINATE_ALLEGRO<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
<a href="http://www.allegro.cc/manual/END_OF_MAIN" target="_blank"><span class="a">END_OF_MAIN</span></a><span class="k2">(</span><span class="k2">)</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ReyBrujo)</author>
		<pubDate>Sat, 07 Aug 2004 04:15:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
No, making a game almost entirely out of templates is evil. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Sat, 07 Aug 2004 04:17:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">spellcaster said:</div><div class="quote"><p>
As long as there&#39;s no way to replace the # and ## macro operations, there&#39;s a need for defines. It&#39;s that easy.
</p></div></div><p>
spellcaster, you&#39;re seriously pissing me off with this straw man. 95% of all instances of macros I ever saw at Allegro.cc were unjustified and then you bring up a few exotic uses of it where it <i>might</i> be useful supposedly as a rebuttal?</p><p>I stand by the statement that macros should be minimized AS MUCH AS POSSIBLE and so should you. Frankly, you&#39;re not helping changing the general mindset here.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Rash)</author>
		<pubDate>Sat, 07 Aug 2004 04:17:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>spellcaster, you&#39;re seriously pissing me off with this straw man</p></div></div><p>

Who&#39;s strawmanning here, eh? Allegro&#39;s use of macros was not mentioned once prior to spellcaster saying that line, and he didn&#39;t mention it either.</p><p>EDIT: For the record, Rash&#39;s post said &quot;... I ever saw in Allegro ...&quot; before he edited it. Not that it matters; the topic of &quot;95% of instances of macros on Allegro.cc&quot; wasn&#39;t brought up either. One broad statement was made, and a casual comment was made disfavoring that statement. Someone needs to lay off the alkaloids...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Sat, 07 Aug 2004 04:21:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
I already mentioned MIN, MID, MAX are useful to me. So what&#39;s wrong with using them?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Richard Phipps)</author>
		<pubDate>Sat, 07 Aug 2004 04:21:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>I already mentioned MIN, MID, MAX are useful to me. So what&#39;s wrong with using them?</p></div></div><p>

Inlined versions are safer. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /> A Google for the MIN macro (just for the sake of double checking what I was about to say) coughs up <a href="http://www.google.ca/url?sa=U&amp;start=1&amp;q=http://lists.gnu.org/archive/html/bug-guile/2004-04/msg00056.html&amp;e=7370">&quot;MIN macro in numbers.c causes build problems on HP-UX&quot;</a> as the first hit. <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /> <a href="http://www.google.ca/url?sa=U&amp;start=4&amp;q=http://www.redhat.com/docs/manuals/enterprise/RHEL-3-Manual/cpp/macro-arguments.html&amp;e=7370">Fourth hit</a> demonstrates some problems (&quot;In this small example you can already see several of the dangers of macro arguments ...&quot;)</p><p>Macros have uses, but very specialized ones. For the purposes of this discussion, in regards to the above code, macros are evil.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Sat, 07 Aug 2004 04:23:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
These are the same as those defined by allegro?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Richard Phipps)</author>
		<pubDate>Sat, 07 Aug 2004 04:25:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
The MIN() macro is pretty much the same everywhere ...</p><div class="source-code snippet"><div class="inner"><pre>   <span class="p">#define min(X, Y)  ((X) &lt; (Y) ? (X) : (Y))</span>
</pre></div></div><p>
Makes me sick, it does. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /> An inlined template function is much better. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /> IMHO, of course ....
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Sat, 07 Aug 2004 04:26:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>DJGPP has another, using the __typeof to prevent errors this macro has.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ReyBrujo)</author>
		<pubDate>Sat, 07 Aug 2004 04:27:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
looks ok to me. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Richard Phipps)</author>
		<pubDate>Sat, 07 Aug 2004 04:30:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="source-code snippet"><div class="inner"><pre>
   a <span class="k3">=</span> MIN<span class="k2">(</span><span class="k3">-</span><span class="k3">-</span>b, <span class="k3">+</span><span class="k3">+</span>c<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
Depending on whether you&#39;re using the macro or an inlined function, you&#39;ll get two different results for &#39;a&#39;.</p><p>EDIT: The &quot;expensive_computation&quot; argument is another good one ...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Sat, 07 Aug 2004 04:33:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>looks ok to me.</p></div></div><p>

<span class="source-code">min<span class="k2">(</span>expensive_computation<span class="k2">(</span><span class="k2">)</span>, another_expensive_computation<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span></span></p><p>...after cpp...</p><p><span class="source-code"><span class="k2">(</span>expensive_computation<span class="k2">(</span><span class="k2">)</span> <span class="k3">&lt;</span> another_expensive_computation<span class="k2">(</span><span class="k2">)</span> ? expensive_computation<span class="k2">(</span><span class="k2">)</span> <span class="k2">:</span> another_expensive_computation<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span></span></p><p>Just one example of why it&#39;s evil. Either way the &quot;winner&quot; is going to have to be executed twice. If either has side effects, you&#39;re even further up sh*t creek...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Sat, 07 Aug 2004 04:34:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="source-code snippet"><div class="inner"><pre><span class="k1">int</span> a <span class="k3">=</span> <span class="n">9</span><span class="k2">;</span>
<span class="k1">int</span> b <span class="k3">=</span> <span class="n">10</span><span class="k2">;</span>
<span class="k1">int</span> c <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>

c <span class="k3">=</span> MIN<span class="k2">(</span>a<span class="k3">+</span><span class="k3">+</span>, b<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

Should return 9, returns 10.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ReyBrujo)</author>
		<pubDate>Sat, 07 Aug 2004 04:34:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
ok.. it is 12:40am here. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>But what about normal variables:<br /><span class="source-code"> c <span class="k3">=</span> MIN<span class="k2">(</span>a, b<span class="k2">)</span><span class="k2">;</span></span></p><p>any problems here?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Richard Phipps)</author>
		<pubDate>Sat, 07 Aug 2004 04:36:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>looks ok to me. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p></div></div><p>

The fact this comment got thrice bum-rushed tells you this is a classic example of evil macros. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>any problems here?</p></div></div><p>

There? No. But wouldn&#39;t you prefer a function that NEVER gives you problems? See the first post; you can shoot yourself in the foot reall easy like ...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Sat, 07 Aug 2004 04:36:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
Or... unsensible use of the macro. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Richard Phipps)</author>
		<pubDate>Sat, 07 Aug 2004 04:36:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Should return 9, but returns 10.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ReyBrujo)</author>
		<pubDate>Sat, 07 Aug 2004 04:36:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>unsensible use of the macro</p></div></div><p>

Just by making it an inline function instead, this kind of misbehaviour is made impossible. You don&#39;t have to care any more, and the function will execute just as fast. Why give you the chance to shoot yourself in the foot if preventing it is just as powerful?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Sat, 07 Aug 2004 04:38:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Or... unsensible use of the macro.</p></div></div><p>

Would you consider it better practice to make bulletproof code that always works, or code that relies on you not to screw it up every time you reference it? The macro has pitfalls, and zero advantages over the inlined template function.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Sat, 07 Aug 2004 04:38:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">rash said:</div><div class="quote"><p>spellcaster, you&#39;re seriously pissing me off with this straw man. 95% of all instances of macros I ever saw at Allegro.cc were unjustified and then you bring up a few exotic uses of it where it might be useful supposedly as a rebuttal?</p></div></div><p>

I think I got that covered, eh?</p><div class="quote_container"><div class="title">myself said:</div><div class="quote"><p>I agree that inline functions and constants / enums should be used where it is possible.</p></div></div><p>

I think you should apologize. And maybe you should read the posts you&#39;re replying to, and maybe even think twice before you post once. Just an idea.</p><p>Anyway, saying that macros are &quot;evil, evil, evil&quot; is singleminded. And not very clever. Due to the idea that all a macro can do is just text replacement, nobody cares about the cpp anymore. Most don&#39;t even know about the # and ## operators and how to use them. </p><p>But, from time to time macros are extremly useful, make your code more easy to read and more easy to maintain.</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">unsigned</span> <span class="k1">char</span> flags <span class="k3">=</span> BINARY2<span class="k2">(</span> <span class="n">1001</span>, <span class="n">0011</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
is more easy to read and less error prone than the decimal or hexadecimal  version of that number.</p><div class="source-code snippet"><div class="inner"><pre>assertmsg<span class="k2">(</span> value <span class="k3">&gt;</span> <span class="n">0</span>, <span class="s">"The value must be &gt; 0"</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
will give you a better error message than a pure assert().</p><p>Macros allow to create a string containing both file name and line number... which is quite neat, IMO.</p><p>The point is: cpp is a tool. If you use it wisely, it&#39;ll help you. If you use it poorly, well, than you&#39;re not clever enough.</p><p>Always use the right tool for the right job. Should one use a #define for constants or should one prefer enums or consts? In that case the define looses.<br />Samething for macros and inline functions (most of the time).</p><p>But: Just because there are better ways for these two jobs doesn&#39;t mean that &quot;macros are evil&quot;. And whoever telling you that macros are evil never read the cpp description <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /><br />All it means that you shouldn&#39;t use macros for constants and inline methods. It&#39;s as easy as that.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (spellcaster)</author>
		<pubDate>Sat, 07 Aug 2004 04:38:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
&lt;shrugs&gt;</p><p>I only use it as: <span class="source-code">c <span class="k3">=</span> MIN<span class="k2">(</span>a, b<span class="k2">)</span><span class="k2">;</span></span> anyway.</p><p>And on that note, I&#39;m off to bed. If I can sleep in this stifling heat..
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Richard Phipps)</author>
		<pubDate>Sat, 07 Aug 2004 04:39:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">X-G said:</div><div class="quote"><p>
EDIT: For the record, Rash&#39;s post said &quot;... I ever saw in Allegro ...&quot; before he edited it.
</p></div></div><p>
You must be imagining things, because I did no such thing.</p><p>Ten to one this thread will now degenerate into a C vs C++ vs C99 discussion...Oh wait! <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Rash)</author>
		<pubDate>Sat, 07 Aug 2004 04:41:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>All it means that you shouldn&#39;t use macros for constants and inline methods. It&#39;s as easy as that.</p></div></div><p>

Right. But that&#39;s what most people use them for, like it or not. Like, you know, above. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> <a href="http://www.allegro.cc/forums/view_thread.php?_id=250384#target">Remember this post?</a> Teach the acolyte that macros are evil. When he is a wizard, he can use the black magic when necessary. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><p>William Labbett: MACROS AER TEH EVAL!!1 RUNRUNRUNRUN ...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Sat, 07 Aug 2004 04:42:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Teach the acolyte that macros are evil.</p></div></div><p>
That&#39;s not needed. Teach everybody that he should use consts and enums for constant values, and inline functions for inline functions.</p><p>That&#39;s it. No black magic involved here.</p><p>EDIT:<br />Rash: I either want your macro less way for the normal uses of # and ## inside macros, or an apology...<br />On the other hand, no apology and no macro less way would prove my point as well <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (spellcaster)</author>
		<pubDate>Sat, 07 Aug 2004 04:45:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Here&#39;s a great opportunity to mold a young mind... How would an inlined template-using MIN look? (i have no idea how templates work, but im sure it can be useful <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Jonatan Hedborg)</author>
		<pubDate>Sat, 07 Aug 2004 05:41:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
I assume something like:</p><p><span class="source-code"><span class="k1">inline</span> <span class="k1">template</span> <span class="k3">&lt;</span><span class="k1">typename</span> T&gt; T min<span class="k2">(</span>T a, T b<span class="k2">)</span> <span class="k2">{</span> <span class="k1">return</span> <span class="k2">(</span>a <span class="k3">&lt;</span> b ? a <span class="k2">:</span> b<span class="k2">)</span><span class="k2">;</span> <span class="k2">}</span></span></p><p>EDIT: Forgot return type. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Sat, 07 Aug 2004 05:46:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
Off the top of my head ...</p><div class="source-code snippet"><div class="inner"><pre>   <span class="k1">template</span><span class="k3">&lt;</span><span class="k1">class</span> T&gt;
   <span class="k1">inline</span> T cadd<span class="k2">(</span>T x, T y<span class="k2">)</span>
   <span class="k2">{</span>
     <span class="k1">return</span> <span class="k2">(</span>x <span class="k3">&lt;</span> y ? x <span class="k2">:</span> y<span class="k2">)</span><span class="k2">;</span>
   <span class="k2">}</span>
</pre></div></div><p>
I might have goofed; it&#39;s untested ...</p><p>EDIT: All fixed.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Sat, 07 Aug 2004 05:46:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok, to stay in character I&#39;ll make my 1000th post useful:</p><div class="source-code snippet"><div class="inner"><pre><span class="p">#include &lt;algorithm&gt;</span>
std::min<span class="k2">(</span>a,b<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
[EDIT]<br />No need to reinvent the wheel, is there?<br />[/EDIT]
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Rash)</author>
		<pubDate>Sat, 07 Aug 2004 05:48:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>X-G: Your code didnt compile.<br />23: your code worked after i replaced X with z1 and Y with z2 <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Jonatan Hedborg)</author>
		<pubDate>Sat, 07 Aug 2004 05:51:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>No need to reinvent the wheel, is there?</p></div></div><p>

No need to include a standard header for four lines, either. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /> He did ask to see what it would look like ...
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>23: your code worked after i replaced X with z1 and Y with z2</p></div></div><p>

Whoops; right. <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /> That&#39;s what I get for copying off of Google. <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" /> All fixed.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Sat, 07 Aug 2004 05:52:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>X-G: Your code didnt compile.</p></div></div><p>

How about telling me WHY? <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /> Mine is identical to 23&#39;s, apart from the placement of &quot;inline&quot; and line breaks/parentheses that shouldn&#39;t matter...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Sat, 07 Aug 2004 05:52:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
I think it&#39;s the inline placement, X-G ...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Sat, 07 Aug 2004 05:53:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I dont know WHY, but im sure this can help <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td>g<span class="k3">+</span><span class="k3">+</span>.exe <span class="k3">-</span>c main.cpp <span class="k3">-</span>o main.o <span class="k3">-</span>I<span class="s">"C:/Dev-Cpp/include/c++"</span>  <span class="k3">-</span>I<span class="s">"C:/Dev-Cpp/include/c++/mingw32"</span>  <span class="k3">-</span>I<span class="s">"C:/Dev-Cpp/include/c++/backward"</span>  <span class="k3">-</span>I<span class="s">"C:/Dev-Cpp/include"</span>   </td></tr><tr><td class="number">2</td><td>&#160;</td></tr><tr><td class="number">3</td><td>main.cpp:5: error: syntax error before `<span class="k3">&lt;</span><span class="s">' token</span></td></tr><tr><td class="number">4</td><td><span class="s">main.cpp:8: error: definition provided for explicit instantiation</span></td></tr><tr><td class="number">5</td><td><span class="s">main.cpp:8: error: non-template used as template</span></td></tr><tr><td class="number">6</td><td><span class="s">main.cpp:8: error: syntax error before `{'</span> token</td></tr><tr><td class="number">7</td><td>main.cpp:12: error: ISO C<span class="k3">+</span><span class="k3">+</span> forbids declaration of `<a href="http://www.delorie.com/djgpp/doc/libc/libc_802.html" target="_blank">system</a><span class="s">' with no type</span></td></tr><tr><td class="number">8</td><td><span class="s">main.cpp:12: error: `int std::system'</span> redeclared as different kind of symbol</td></tr><tr><td class="number">9</td><td>C:<span class="k3">/</span>Dev-Cpp<span class="k3">/</span>include<span class="k3">/</span>stdlib.h:362: error: previous declaration of `<span class="k1">int</span> </td></tr><tr><td class="number">10</td><td>   <a href="http://www.delorie.com/djgpp/doc/libc/libc_802.html" target="_blank">system</a><span class="k2">(</span><span class="k1">const</span> <span class="k1">char</span><span class="k3">*</span><span class="k2">)</span><span class="s">'</span></td></tr><tr><td class="number">11</td><td><span class="s">main.cpp:12: error: invalid conversion from `const char*'</span> to `<span class="k1">int</span><span class="s">'</span></td></tr><tr><td class="number">12</td><td><span class="s"></span></td></tr><tr><td class="number">13</td><td><span class="s">main.cpp:13: error: syntax error before `return'</span></td></tr><tr><td class="number">14</td><td>&#160;</td></tr><tr><td class="number">15</td><td>C:<span class="k3">/</span>Dev-Cpp<span class="k3">/</span>include<span class="k3">/</span>c<span class="k3">+</span><span class="k3">+</span><span class="k3">/</span><span class="n">3</span>.<span class="n">3</span>.<span class="n">1</span><span class="k3">/</span>iostream:77: error: definition provided <span class="k1">for</span> </td></tr><tr><td class="number">16</td><td>   <span class="k1">explicit</span> instantiation</td></tr><tr><td class="number">17</td><td>C:<span class="k3">/</span>Dev-Cpp<span class="k3">/</span>include<span class="k3">/</span>c<span class="k3">+</span><span class="k3">+</span><span class="k3">/</span><span class="n">3</span>.<span class="n">3</span>.<span class="n">1</span><span class="k3">/</span>iostream:77: error: non-template used as <span class="k1">template</span></td></tr><tr><td class="number">18</td><td>C:<span class="k3">/</span>Dev-Cpp<span class="k3">/</span>include<span class="k3">/</span>c<span class="k3">+</span><span class="k3">+</span><span class="k3">/</span><span class="n">3</span>.<span class="n">3</span>.<span class="n">1</span><span class="k3">/</span>iostream:77: confused by earlier errors, bailing out</td></tr></tbody></table></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Jonatan Hedborg)</author>
		<pubDate>Sat, 07 Aug 2004 05:55:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Rash: I think my point is proven then, eh?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (spellcaster)</author>
		<pubDate>Sat, 07 Aug 2004 05:55:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>main.cpp:5: error: syntax error before `&lt;&#39; token</p></div></div><p>

Err, excuse me? That&#39;s where &quot;template&quot; is at. Well, considering how vague errors can be some times, let&#39;s just assume it&#39;s the placement of the word &quot;inline&quot;. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Sat, 07 Aug 2004 05:57:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>yeah, worked when i moved it.. (<span class="source-code"><span class="k1">template</span> <span class="k3">&lt;</span><span class="k1">typename</span> T&gt; <span class="k1">inline</span> T min<span class="k2">(</span>T a, T b<span class="k2">)</span> <span class="k2">{</span> <span class="k1">return</span> <span class="k2">(</span>a <span class="k3">&lt;</span> b ? a <span class="k2">:</span> b<span class="k2">)</span><span class="k2">;</span> <span class="k2">}</span></span>)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Jonatan Hedborg)</author>
		<pubDate>Sat, 07 Aug 2004 05:59:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Make the return value a reference and you&#39;ll have nailed it.</p><p>spellcaster: <a href="http://www.parashift.com/c++-faq-lite/big-picture.html#faq-6.14">http://www.parashift.com/c++-faq-lite/big-picture.html#faq-6.14</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Rash)</author>
		<pubDate>Sat, 07 Aug 2004 06:02:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Make the return value a reference and you&#39;ll have nailed it.</p></div></div><p>

Return a reference? I can see the parameters as references, but by constructing the object right on the return statement ... well, I didn&#39;t know you could beat that. I might be wrong, but what are we returning a reference to?</p><p>BTW, that is the coolest new entry into the C++ FAQ Lite ever. <img src="http://www.allegro.cc/forums/smileys/cool.gif" alt="8-)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Sat, 07 Aug 2004 06:15:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well in that case make the parameters references as well. The declaration of <i>std::min</i>, after all, is:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">template</span> <span class="k3">&lt;</span><span class="k1">class</span> T&gt; <span class="k1">const</span> T<span class="k3">&amp;</span> min<span class="k2">(</span><span class="k1">const</span> T<span class="k3">&amp;</span> a, <span class="k1">const</span> T<span class="k3">&amp;</span> b<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Rash)</author>
		<pubDate>Sat, 07 Aug 2004 06:21:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>rash: what&#39;s your point?<br />Please read your own post. Then my reply. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /><br />Then think. </p><p>You even quoted me saying that there are uses for macros. Then you replied that this &quot;pisses you off&quot;.<br />I guess this means that you either have a better way to handle these situations, or that you either impolite and/or challenged by the concept of independent thought, and thus need to repeat the old dogmas (&quot;Macros are evil, sha-la-la-la&quot;).</p><p>While I can understand the latter, you&#39;ve still been rude <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (spellcaster)</author>
		<pubDate>Sat, 07 Aug 2004 06:34:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Wouldn&#39;t it be hard to create an inline min() that handles floats, doubles, chars, and ints, without using C++? That&#39;s one of the problems I had with my game, I had inline min()/max() functions, but they were messing up because it took ints, but I was passing floats (though I wasn&#39;t initially aware of this). I changed them to defines like Allegro has and now it works hunky-dory.</p><p>Though I do kinda wish the inline functions worked.. branchless min/max is a good thing to have.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kitty Cat)</author>
		<pubDate>Sat, 07 Aug 2004 06:43:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>KC, you could send a third parameter stating the type of the parameters you are sending. As for creating one, this is how DJGPP defines it:</p><div class="source-code snippet"><div class="inner"><pre><span class="p">#define min(X, Y) \</span>
<span class="p">    ({ typeof (X) __x = (X), __y = (Y); (__x &lt; __y) ? __x : __y }) </span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ReyBrujo)</author>
		<pubDate>Sat, 07 Aug 2004 09:48:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You know you use too much macros, when you demand syntax hilightning in them.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Johan Halmén)</author>
		<pubDate>Sat, 07 Aug 2004 09:54:08 +0000</pubDate>
	</item>
</rss>
