<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Header variable reference bug</title>
<description> So I&amp;#039;ve been updating one of my 3d games in c and I notice that when every I reference a bool variable that was declared in a header file I get a crash screen. If I initialize the variable to false, everything works fine but I am wondering if I am miss using the the header files or something.

My set up is like this;

common.h has this code;

#ifndef common_h
#define common_h
bool debug;
#endif

main.c has this code;

include common.h

bool *myboolv;
void store( bool *boolv ){
myboolv = boolv;

}
void check_value(){
if( *boolv == true) { /* crashes on this if statement */ }
}
void main(){
store(&amp;debug);
check_value();
}

common.c doesn&amp;#039;t have anything in it. If I initialize debug in the main it works fine but other wise I not sure why I getting the error.</description><link>http://forum.wiibrew.org/read.php?11,70677,70677#msg-70677</link><lastBuildDate>Sat, 18 Apr 2026 09:02:43 +0200</lastBuildDate>
<generator>Phorum 5.2.23</generator>
<item>
<guid>http://forum.wiibrew.org/read.php?11,70677,70680#msg-70680</guid>
<title>Re: Header variable reference bug</title><link>http://forum.wiibrew.org/read.php?11,70677,70680#msg-70680</link><description><![CDATA[ Ok, cool, I thought the ifndef was suppose to take care of the. I am working on my menu system. will test out the extern syntax and see if it solves it.]]></description>
<dc:creator>owen</dc:creator>
<category>Coding</category><pubDate>Fri, 08 Jun 2012 04:29:51 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,70677,70679#msg-70679</guid>
<title>Re: Header variable reference bug</title><link>http://forum.wiibrew.org/read.php?11,70677,70679#msg-70679</link><description><![CDATA[ Sounds like there&#039;s more to it (check_value() is dereferencing *boolv which isn&#039;t declared globally), but you shouldn&#039;t be <i>defining</i> variables in header files (especially if they will be included in several .c files). You will end up getting compilation errors caused by multiple global variables with the same names.<br /><br />What you want to do is <i>declare</i> it using the "extern" keyword in the header file, then declare it again in one (and only one) .c file without the extern keyword. That will make it accessible by all .c files that include the header, but only the .c file that contains the non-extern declaration will actually allocate memory space for it.]]></description>
<dc:creator>tueidj</dc:creator>
<category>Coding</category><pubDate>Thu, 07 Jun 2012 22:52:34 +0200</pubDate></item>
<item>
<guid>http://forum.wiibrew.org/read.php?11,70677,70677#msg-70677</guid>
<title>Header variable reference bug</title><link>http://forum.wiibrew.org/read.php?11,70677,70677#msg-70677</link><description><![CDATA[ So I&#039;ve been updating one of my 3d games in c and I notice that when every I reference a bool variable that was declared in a header file I get a crash screen. If I initialize the variable to false, everything works fine but I am wondering if I am miss using the the header files or something.<br /><br />My set up is like this;<br /><br />common.h has this code;<br /><pre class="bbcode">
#ifndef common_h
#define common_h
bool debug;
#endif</pre><br />main.c has this code;<br /><pre class="bbcode">
include common.h

bool *myboolv;
void store( bool *boolv ){
 myboolv = boolv;

}
void check_value(){
  if( *boolv == true) { /* crashes on this if statement */ }
}
void main(){
 store(&debug);
 check_value();
}</pre><br />common.c doesn&#039;t have anything in it. If I initialize debug in the main it works fine but other wise I not sure why I getting the error.]]></description>
<dc:creator>owen</dc:creator>
<category>Coding</category><pubDate>Thu, 07 Jun 2012 17:56:47 +0200</pubDate></item>
</channel>
</rss>