<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>#define SOMETHING</title>
		<link>http://www.allegro.cc/forums/view/601312</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 21 Aug 2009 00:49:15 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
hi again,</p><p> A question I&#39;ve been wanting to ask is this :-</p><p>I understand that</p><p>#define TWELVE 12</p><p>means that occurences of TWELVE in the source file are replaced with 12.</p><p>.......but I see in lots of code with</p><p>#define MAIN_H<br />#define SOMETHING</p><p>with no replacement text which confuses me.</p><p>are these types of define only relevant to be used with</p><p>#ifndef ?</p><p>any kind of clarification would be much appreciated.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Thu, 20 Aug 2009 02:25:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Not only, but that would be their main use. They are replaced with nothing if used normally.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Thu, 20 Aug 2009 02:34:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Also, sometimes it&#39;s important to <span class="source-code"><span class="p">#define</span></span> something <i>away</i>, which is also very important in programming.</p><p>For example, Windows may have some sort of construct, like <span class="source-code">__declspec</span> that Linux and Mac just don&#39;t use.  The preprocessor macro can then be used to either <span class="source-code"><span class="p">#define</span></span> a macro to be something, or you can just <span class="source-code"><span class="p">#define</span></span> it completely away:</p><div class="source-code snippet"><div class="inner"><pre><span class="p">#ifdef WIN32</span>
<span class="p">#define DECLSPEC __declspec</span>
<span class="p">#else</span>
<span class="p">#define DECLSPEC</span>
<span class="p">#endif</span>

...later...

DECLSPEC <span class="k1">void</span> myfunction<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span>...<span class="k2">}</span>
</pre></div></div><p>

So on Linux, the line above would look like:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> myfunction<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span>...<span class="k2">}</span>
</pre></div></div><p>

while on Windows, it would be:</p><div class="source-code snippet"><div class="inner"><pre>__declspec <span class="k1">void</span> myfunction<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span>...<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (OnlineCop)</author>
		<pubDate>Thu, 20 Aug 2009 03:03:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
okay, so a statement like</p><p>#ifndef SOME_HEADER</p><p>basically is true</p><p>if there was a #define SOME_HEADER statement before it, or false if not.</p><p>Is that right ?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Thu, 20 Aug 2009 03:04:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kazzmir)</author>
		<pubDate>Thu, 20 Aug 2009 03:05:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>thanks all,</p><p>regarding this</p><div class="source-code snippet"><div class="inner"><pre>__declspec <span class="k1">void</span> myfunction<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span>...<span class="k2">}</span>
</pre></div></div><p>

I&#39;ve seen a lot of code with something before a type but the only ones I understand are the ones like unsigned, long, const, etc..</p><p>I noticed the allegro code has a lot of these but I don&#39;t understand their purpose, what they mean or how to implement them.</p><p>There doesn&#39;t seem to be much help on them in the K&amp;R C book I have.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Thu, 20 Aug 2009 03:10:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>There are lots of function modifiers you can add that are not part of pure C (except for maybe inline, I dunno). They are extensions added by your compiler (msvc, gcc, etc.)</p><p>__declspec refers to the way arguments are placed on the stack when the function is called. You can either do first argument on the bottom of the stack or first argument on the top of the stack. I forget which __declspec is, but thats the windows way IIRC.</p><p>So basically you need to add __declspec if you are trying to call a windows function. On unix it uses the other way so you can either explicitly say the type (I forget what it is) or just leave it off and gcc will default to the unix way.</p><p>msvc probably defaults to __declspec, I imagine.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kazzmir)</author>
		<pubDate>Thu, 20 Aug 2009 03:19:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><span class="source-code">__declspec</span> is like GCC&#39;s <span class="source-code">__attribute__</span>. It specifies special declaration options. Eg, <span class="source-code">__declspec<span class="k2">(</span>dllimport<span class="k2">)</span></span> tells the compiler that the function is imported from a DLL and not statically linked (it needs to know so it can add a special symbol prefix and tie it to a specific DLL at link-time).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kitty Cat)</author>
		<pubDate>Thu, 20 Aug 2009 03:32:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>right, thanks.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Thu, 20 Aug 2009 03:37:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Oh yea I was confused, ignore most of what I said and read this instead <a href="http://unixwiz.net/techtips/win32-callconv.html">http://unixwiz.net/techtips/win32-callconv.html</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kazzmir)</author>
		<pubDate>Thu, 20 Aug 2009 05:44:17 +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/601312/826059#target">William Labbett</a> said:</div><div class="quote"><p>K&amp;R C book</p></div></div><p>

K&amp;R? <i>Really?</i> I would update my references if I was you. K&amp;R was written in 1978 and hasn&#39;t been valid for decades.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Thu, 20 Aug 2009 23:41:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Okay, I&#39;ll take a look in a book shop next time I go into Norwich.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Thu, 20 Aug 2009 23:43:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>[rant]<br />Okay, first of all, don&#39;t derail this based on my puny reference to <span class="source-code">__declspec</span>.  I&#39;ve never even used it myself.  Ever.  I don&#39;t even know <i>how</i> or <i>what</i> I&#39;d use it for.  I&#39;m just not that good of a programmer yet.</p><p>I was just using it to answer the OP.<br />[/rant]</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><span class="c">// Before this file had ever been #include'd, this had NOT been #define'd</span>
<span class="number">  2</span><span class="p">#ifndef _MY_HEADER_GUARD_</span>
<span class="number">  3</span>
<span class="number">  4</span><span class="c">// NOW it's defined</span>
<span class="number">  5</span><span class="p">#define _MY_HEADER_GUARD_</span>
<span class="number">  6</span>
<span class="number">  7</span><span class="c">// your code here...</span>
<span class="number">  8</span>
<span class="number">  9</span><span class="p">#endif</span>
</div></div><p>

Now if you try to <span class="source-code"><span class="p">#include "that_header_file.h"</span></span> more than one time, your compiler will see that, oops, yes, it&#39;s already been &quot;defined&quot; and won&#39;t re-include it.</p><p>Conversely, Windows declares &quot;BITMAP&quot; in &quot;windows.h&quot;.  So if you compile allegro for Windows, we <span class="source-code"><span class="p">#include "winalleg.h"</span></span>, which redefines all Allegro <span class="source-code"><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a></span>s to something like <span class="source-code">AL_BITMAP</span> using <span class="source-code"><span class="p">#define</span></span>s, making Allegro play nice with Windows.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (OnlineCop)</author>
		<pubDate>Thu, 20 Aug 2009 23:47: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/601312/826181#target">X-G</a> said:</div><div class="quote"><p>K&amp;R was written in 1978 and hasn&#39;t been valid for decades.</p></div></div><p>
One presumes he&#39;s referring to the second edition. That&#39;s still missing the latest additions (from C99), but other than that it&#39;s still both valid and relevant because C hasn&#39;t changed that much.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Thu, 20 Aug 2009 23:48:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
Yes, I have the second edition. I like it because they know what they&#39;re talking about and it&#39;s not a big book. I might aswell use the web for C99 things.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Fri, 21 Aug 2009 00:49:15 +0000</pubDate>
	</item>
</rss>
