<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Interdependant Headers</title>
		<link>http://www.allegro.cc/forums/view/591440</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 18 May 2007 06:39:42 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I am trying to make my first game with more than one header. I have: main.cpp, mmm_aux, and mmm_drawing. Aux is globals, consts, and other trashy one-use functions. Drawing, is, well, drawing. I need to use mmm.dat, declared in Aux (globally declared) in Drawing. My includes in main are:</p><div class="source-code snippet"><div class="inner"><pre><span class="c">/*INCLUDES*/</span>
<span class="p">#include &lt;cmath&gt;</span>
<span class="p">#include &lt;ctime&gt;</span>
<span class="p">#include &lt;string.h&gt;</span>
<span class="p">#include "mmm_aux.h"</span>
<span class="p">#include "mmm_drawing.h"</span>
<span class="p">#include "MMM.h"</span>
<span class="p">#include &lt;allegro.h&gt;</span>
</pre></div></div><p>

In Aux, mmm is declared as:
</p><div class="source-code snippet"><div class="inner"><pre><span class="c">/*INCLUDES*/</span>
<span class="p">#include &lt;allegro.h&gt;</span>
<span class="c">/*THINGS*/</span>
<a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>buffy<span class="k2">;</span>
<a href="http://www.allegro.cc/manual/DATAFILE" target="_blank"><span class="a">DATAFILE</span></a> <span class="k3">*</span>mmm<span class="k2">;</span>
</pre></div></div><p>

then set in a function in Aux, game_setup(), as 
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> game_setup<span class="k2">(</span><span class="k2">)</span><span class="k2">{</span>
  <a href="http://www.delorie.com/djgpp/doc/libc/libc_739.html" target="_blank">srand</a><span class="k2">(</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_821.html" target="_blank">time</a><span class="k2">(</span>NULL<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
  buffy <span class="k3">=</span> <a href="http://www.allegro.cc/manual/create_bitmap" target="_blank"><span class="a">create_bitmap</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/SCREEN_W" target="_blank"><span class="a">SCREEN_W</span></a>, <a href="http://www.allegro.cc/manual/SCREEN_H" target="_blank"><span class="a">SCREEN_H</span></a><span class="k2">)</span><span class="k2">;</span>
  mmm <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_datafile" target="_blank"><span class="a">load_datafile</span></a><span class="k2">(</span><span class="s">"MMM.dat"</span><span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

But, when I use this function in Drawing
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> draw_cursor<span class="k2">(</span><span class="k1">float</span> w_range, <span class="k1">int</span> d_x, <span class="k1">int</span> d_y<span class="k2">)</span><span class="k2">{</span>
  <span class="k1">float</span> c2 <span class="k3">=</span> <span class="k2">(</span>d_x<span class="k3">*</span>d_x<span class="k2">)</span><span class="k3">+</span><span class="k2">(</span>d_y<span class="k3">*</span>d_y<span class="k2">)</span><span class="k2">;</span>
  <span class="k1">float</span> distance <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_738.html" target="_blank">sqrt</a><span class="k2">(</span>c2<span class="k2">)</span><span class="k2">;</span>
  <span class="k1">if</span><span class="k2">(</span>distance <span class="k3">&lt;</span> w_range<span class="k2">)</span>
    <a href="http://www.allegro.cc/manual/masked_blit" target="_blank"><span class="a">masked_blit</span></a><span class="k2">(</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a><span class="k3">*</span><span class="k2">)</span>mmm<span class="k2">[</span>crosshair<span class="k2">]</span>.dat, buffy, <span class="n">0</span>, <span class="n">0</span>, mouse_x-16, mouse_y-16, <span class="n">32</span>, <span class="n">32</span><span class="k2">)</span><span class="k2">;</span>
  <span class="k1">else</span>
    <a href="http://www.allegro.cc/manual/masked_blit" target="_blank"><span class="a">masked_blit</span></a><span class="k2">(</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a><span class="k3">*</span><span class="k2">)</span>mmm<span class="k2">[</span>crosshair<span class="k2">]</span>.dat, buffy, <span class="n">32</span>, <span class="n">0</span>, mouse_x-16, mouse_y-16, <span class="n">32</span>, <span class="n">32</span><span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

It says:<br />error C2065: &#39;crosshair&#39; undeclared identifier<br />error C2228: left of &#39;.dat&#39; must have class/struct/union</p><p>What am I doing wrong?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SkaxCo)</author>
		<pubDate>Fri, 18 May 2007 04:48:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Where do you define the &quot;crosshair&quot; variable? I can&#39;t see it anywhere and so does the compiler<br />Use -&gt;dat instead of .dat, mmm is a pointer.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (HoHo)</author>
		<pubDate>Fri, 18 May 2007 05:03:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>crosshair is a bitmap in mmm.dat. This code worked if I put it in the main body of code in main.cpp.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SkaxCo)</author>
		<pubDate>Fri, 18 May 2007 05:06:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Assuming that this isa preprocessor define created by dat utility you need to get the definitions in the .h that came with the .dat into the .cpp file that does the drawing. I think it is called MMM.h in your case but I might be wrong.</p><p>If it is just some random global you created yourself you need to learn extern variables. Long story short: don&#39;t define variables in headers, define them in sources and have extern versions of them in other sources/headers
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (HoHo)</author>
		<pubDate>Fri, 18 May 2007 05:11:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, I was forgetting to include MMM.h.</p><p>I&#39;m going to try to decipher what you said and use it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SkaxCo)</author>
		<pubDate>Fri, 18 May 2007 05:14:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Extern variables are actually relatively simple, just google for them or search the forum, there was some discussion about it some time ago. If anything is unclear feel free to come back and ask guidance
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (HoHo)</author>
		<pubDate>Fri, 18 May 2007 05:18:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Wait...so, in Drawing, in game_setup(), I would do something like
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">extern</span> <a href="http://www.allegro.cc/manual/DATAFILE" target="_blank"><span class="a">DATAFILE</span></a> <span class="k3">*</span>mmm<span class="k2">;</span>
mmm <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_datafile" target="_blank"><span class="a">load_datafile</span></a><span class="k2">(</span><span class="s">"MMM.dat"</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>?</p><p>Because that didn&#39;t work.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SkaxCo)</author>
		<pubDate>Fri, 18 May 2007 05:28:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>In your header, you want<br /><span class="source-code"><span class="k1">extern</span> <a href="http://www.allegro.cc/manual/DATAFILE" target="_blank"><span class="a">DATAFILE</span></a> <span class="k3">*</span>mmm<span class="k2">;</span> <span class="c">//declaration</span></span><br />and in your source file, you want<br /><span class="source-code"><a href="http://www.allegro.cc/manual/DATAFILE" target="_blank"><span class="a">DATAFILE</span></a> <span class="k3">*</span>mmm <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_datafile" target="_blank"><span class="a">load_datafile</span></a><span class="k2">(</span><span class="s">"MMM.dat"</span><span class="k2">)</span><span class="k2">;</span> <span class="c">//definition</span></span></p><p>You have to have one formal definition of it like that, because extern just says &quot;Yes, mmm exists somewhere, you just have to go find it&quot; and the definition says &quot;Here I am!&quot;.</p><p>Make sense?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kibiz0r)</author>
		<pubDate>Fri, 18 May 2007 05:38:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>So I redefine it in each file? Ok, I got it, and it works. But...unrelated...my computer sucks so much, my parents are too cheap to improve it, and I can&#39;t get a job. They only got a new cooling system when it was overheating so much it wouldn&#39;t boot, and a new video card when some games I bought wouldn&#39;t run. I have like a 1.2 GHz processor and 512 of crappy RAM.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SkaxCo)</author>
		<pubDate>Fri, 18 May 2007 06:07:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
So I redefine it in each file?
</p></div></div><p>

No, only define it once, in the .c/.cpp file you want to define the value in.</p><p>Any file you want to use it in, it has to be declared, using extern. You will probably accomplish this by including a header, though, to save time declaring it all over the place.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kibiz0r)</author>
		<pubDate>Fri, 18 May 2007 06:32:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You are talking to a computer.  You must speaketh their language, but if you want a rough, un-technical translation, the word &quot;extern&quot; is bascially saying &quot;I promise to declare this in my cpp file, honestly, so if anyone wants to know, it&#39;s in the cpp...honestly.&quot;  </p><p>Don&#39;t break promises to the computer, they get angry.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Onewing)</author>
		<pubDate>Fri, 18 May 2007 06:39:42 +0000</pubDate>
	</item>
</rss>
