<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Randomly changing variable</title>
		<link>http://www.allegro.cc/forums/view/591565</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sun, 27 May 2007 10:08:44 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Can we please brainstorm for a minute why an integer variable might spontaneously reset to zero? This thing gets explicitly assigned nowhere but in a SetState() function, which does not allow 0 to be assigned to it. Elsewhere, I have code to check if the value is ever equal to 0, and it occasionally is. The only reason I can think of that that might happen is if there&#39;s sort of buffer overrun out of an array, but this variable is cushioned by a large number of other single variables (ie: it&#39;s nowhere near an array in memory), and this happens in multiple objects. So I guess it&#39;s unlikely, but I can&#39;t think of what else might do that. Any other ideas?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Fri, 25 May 2007 06:44:32 +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 guess it&#39;s unlikely, but I can&#39;t think of what else might do that.
</p></div></div><p>
Neither can I.  What all debugging process have you tried?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Onewing)</author>
		<pubDate>Fri, 25 May 2007 06:49:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Sleep on it.  Repeat if necessary.  <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (nonnus29)</author>
		<pubDate>Fri, 25 May 2007 07:33:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Optimizations? Did you try disabling optimization or declaring it volatile?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Fri, 25 May 2007 07:42:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Sometimes a buffer overflow fill variables with some strange values. The last pointer problem I had was caused by such a thing. ptr = NULL ; if( ptr == NULL ) do nothing ; but ptr wasn&#39;t NULL as a for() loop with a char toto[it] overwritten it.</p><p>Launch GDB, set a breakpoint at main, and go step by step, check the variable value.</p><p>Try launching your code trough valgrind.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (GullRaDriel)</author>
		<pubDate>Fri, 25 May 2007 13:10:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The first thing that comes to mind is you&#39;ve done something like this:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> SetVarible <span class="k2">(</span><span class="k1">int</span> var<span class="k2">)</span>
<span class="k2">{</span>
  var <span class="k3">=</span> <span class="n">1</span><span class="k2">;</span>
<span class="k2">}</span>

<span class="k1">void</span> main <span class="k2">(</span><span class="k1">void</span><span class="k2">)</span>
<span class="k2">{</span>
  <span class="k1">int</span> v<span class="k2">;</span>
  SetVariable<span class="k2">(</span>v<span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

When you pass a pointer or variable to a function, it is <i>copied</i> into the function. If you want to change the value of a variable passed to a function, you need to make it a reference like this:</p><p><span class="source-code"><span class="k1">void</span> SetVarible <span class="k2">(</span><span class="k1">int</span> <span class="k3">&amp;</span>var<span class="k2">)</span></span></p><p>This counts for pointers as well. If you want to change where a pointer passed to a function is pointing to it needs to be a reference to a pointer.</p><p>If you don&#39;t make it a reference, any changes you make to the variable/pointer will only affect said function.</p><p>--- Kris Asick (Gemini)<br />--- <a href="http://www.pixelships.com">http://www.pixelships.com</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kris Asick)</author>
		<pubDate>Fri, 25 May 2007 13:20:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>My vote goes for a buffer over/under run, or a <i>boofed</i> pointer. If all else fails look for uninitialized variables.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Sirocco)</author>
		<pubDate>Fri, 25 May 2007 16:28:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Valgrind would spot this in a few seconds <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CGamesPlay)</author>
		<pubDate>Fri, 25 May 2007 16:30:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Elsewhere, I have code to check if the value is ever equal to 0, and it occasionally is.
</p></div></div><p>
Does that code look like this:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span> <span class="k2">(</span>evil_variable <span class="k3">=</span> <span class="n">0</span><span class="k2">)</span> <span class="k2">{</span>
   <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"OMFG!"</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 (miran)</author>
		<pubDate>Fri, 25 May 2007 16:53:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well that wouldn&#39;t work. blah=0 always returns 0, which is false.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Fri, 25 May 2007 16:56:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Oh right... <img src="http://www.allegro.cc/forums/smileys/embarassed.gif" alt=":-[" /></p><p>EDIT:</p><p>What about this:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span> <span class="k2">(</span>evil_variable <span class="k3">=</span> <span class="n">0</span><span class="k2">)</span> <span class="k2">{</span>
   <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"OMFG!"</span><span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>

<span class="c">// then somewhere else</span>

<span class="k1">if</span> <span class="k2">(</span>evil_variable <span class="k3">=</span><span class="k3">=</span> <span class="n">0</span><span class="k2">)</span> <span class="k2">{</span>
   <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"OMFG!"</span><span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
<img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=":D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (miran)</author>
		<pubDate>Fri, 25 May 2007 17:00:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That would work. <img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=":D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Fri, 25 May 2007 17:02:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>GDB has a way to watch memory addresses, so you can set a watchpoint on the variable&#39;s location, run the program, and it&#39;ll break whenever the memory is changed.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kitty Cat)</author>
		<pubDate>Fri, 25 May 2007 20:24:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
My vote goes for a bad pointer too!</p><p>KC&#39;s suggestion to find the problem sounds good too.. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Richard Phipps)</author>
		<pubDate>Fri, 25 May 2007 20:38:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>My vote goes for bad pointer plus memory-corruption/buffer-overflow.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 25 May 2007 21:09:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Did you try disabling optimization or declaring it volatile?
</p></div></div><p>
It&#39;s not volatile. No special optimizations.
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
When you pass a pointer or variable to a function, it is copied into the function.
</p></div></div><p>
Nah, I ain&#39;t that amateur. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /> The value is a private member that gets set nowhere except in its own private Set() function (one that checks for a value of 0, too). I assign to it nowhere else, but I reference it every loop and occasionally discover it&#39;s 0.
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
If all else fails look for uninitialized variables.
</p></div></div><p>
Not that. I&#39;m picky about always initializing.
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Does that code look like this:
</p></div></div><p>
Actually, I just output the variable to file. Says 0.</p><p>I&#39;m still cleaning up the code and making sure there&#39;s no dirty hacks that might be doing this, so maybe it&#39;ll disappear on its own. To my shame, I&#39;m not much of a debugger, I could never get stuff like GDB to work, so I don&#39;t know if I&#39;ll have to resort to that. Main thing that concerned me was if there was something else I hadn&#39;t though of, so I&#39;ll have to check all my array crap.
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Try launching your code trough valgrind.<br />....<br />Valgrind would spot this in a few seconds <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div></div><p>
You Linux people can kiss my butt. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Sat, 26 May 2007 02:51:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
You could try Fortify. It&#39;s free and you can use it with GCC or MingW on Windows. I managed to get it working before, so you should have no problem.. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Richard Phipps)</author>
		<pubDate>Sat, 26 May 2007 02:54:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Most debuggers have a way to watch variables, even break once the variable changes.  You can&#39;t just look through X amount of code and <i>think</i> that you&#39;ve solved the problem manually.  </p><p>What IDE are you using?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Onewing)</author>
		<pubDate>Sat, 26 May 2007 02:57:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
You can&#39;t just look through X amount of code and think that you&#39;ve solved the problem manually.
</p></div></div><p>
If the variable stops reporting 0 after the code is finalized, I can be reasonably certain. <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>
What IDE are you using?
</p></div></div><p>
MinGW and SciTE.</p><p>I&#39;ll look into Fortify if I find the need.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Sat, 26 May 2007 03:03:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This will totally fix it:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span> <span class="k2">(</span>myvar<span class="k3">=</span><span class="k3">=</span><span class="n">0</span><span class="k2">)</span>
<span class="k2">{</span>myvar<span class="k3">=</span><span class="n">1</span><span class="k2">;</span><span class="k2">}</span>
</pre></div></div><p>

Obviously, you didn&#39;t read <a href="http://worsethanfailure.com/Articles/Unconfigurables-Configurables.aspx">Worse Than Failure</a> today...</p><p><img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=":D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Michael Jensen)</author>
		<pubDate>Sat, 26 May 2007 04:37:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That&#39;s basically the current remedy and it works fine, but I prefer knowing how it happened in the first place ...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Sat, 26 May 2007 04:44:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, at least I made myself laugh -- I guess that&#39;s all that matters. <img src="http://www.allegro.cc/forums/smileys/cool.gif" alt="8-)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Michael Jensen)</author>
		<pubDate>Sat, 26 May 2007 04:48:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, depending on the amount of code between when you set it to non-zero and when it gets mysteriously reset to 0, you could always do something like this to try and spot where exactly it changes:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> DoStuff <span class="k2">(</span><span class="k1">void</span><span class="k2">)</span>
<span class="k2">{</span>
  <a href="http://www.allegro.cc/manual/allegro_message" target="_blank"><span class="a">allegro_message</span></a><span class="k2">(</span><span class="s">"A: Value = %d"</span>,myVar<span class="k2">)</span><span class="k2">;</span>
  myVar <span class="k3">=</span> <span class="n">1</span><span class="k2">;</span>
  <a href="http://www.allegro.cc/manual/allegro_message" target="_blank"><span class="a">allegro_message</span></a><span class="k2">(</span><span class="s">"B: Value = %d"</span>,myVar<span class="k2">)</span><span class="k2">;</span>
  <span class="c">// next command goes here</span>
  <a href="http://www.allegro.cc/manual/allegro_message" target="_blank"><span class="a">allegro_message</span></a><span class="k2">(</span><span class="s">"C: Value = %d"</span>,myVar<span class="k2">)</span><span class="k2">;</span>
  <span class="c">// next command goes here</span>
  <a href="http://www.allegro.cc/manual/allegro_message" target="_blank"><span class="a">allegro_message</span></a><span class="k2">(</span><span class="s">"D: Value = %d"</span>,myVar<span class="k2">)</span><span class="k2">;</span>
  <span class="c">// next command goes here</span>
  <a href="http://www.allegro.cc/manual/allegro_message" target="_blank"><span class="a">allegro_message</span></a><span class="k2">(</span><span class="s">"E: Value = %d"</span>,myVar<span class="k2">)</span><span class="k2">;</span>
  <span class="c">// next command goes here</span>
  <a href="http://www.allegro.cc/manual/allegro_message" target="_blank"><span class="a">allegro_message</span></a><span class="k2">(</span><span class="s">"F: Value = %d"</span>,myVar<span class="k2">)</span><span class="k2">;</span>
  <span class="c">// next command goes here</span>
<span class="k2">}</span>
</pre></div></div><p>

It would be nice to see some code. Specifically, I want to see the code for where the variable is created, because my next suspicion is out-of-bound array access.</p><p>--- Kris Asick (Gemini)<br />--- <a href="http://www.pixelships.com">http://www.pixelships.com</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kris Asick)</author>
		<pubDate>Sat, 26 May 2007 14:20:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
If this is a game, maybe display the contents of the variable every frame and see if any parts the game logic chnage it. If it changes straight away then it&#39;s probably something in your inner loop.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Richard Phipps)</author>
		<pubDate>Sat, 26 May 2007 14:32:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Are you using any sort of multi-threading?</p><p>Otherwise make a backup of your project, and then start ripping out chunks of it until the problem goes away. It&#39;s probably wise to find out what it is while it&#39;s occuring regularly.  When you have the same problem, but it only occurs once a week - that is when you start getting worried.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (james_lohr)</author>
		<pubDate>Sat, 26 May 2007 20:21:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I never use debuggers either, just use printf or system.out.println, or whatever.  But this article made me realize that being proficient using debugging tools can give you much powerful programming mojo:</p><p><a href="http://www.ahristov.com/tutorial/Blog/MySQL%2Band%2BData%2BTruncation%2B%3A%2BA%2Bdescent%2Binto%2BIEEE%2Bhell.html">Clickie</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (nonnus29)</author>
		<pubDate>Sat, 26 May 2007 20:58:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Well, depending on the amount of code between when you set it to non-zero and when it gets mysteriously reset to 0, you could always do something like this to try and spot where exactly it changes:
</p></div></div><p>
Geez!<br />People, this is 2007. Learn to use a debugger. I know that gdb seems intimidating first, and that there is no free frontend for it on windows, but for a case like this all you need is too google for a howto, run the game with debug info through gdb and take a look at the callstack.</p><p>Writing to a log is nice to get a log. It&#39;s not a good debugging method. Use it to realize that there is an error, don&#39;t use it to hunt it down.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I never use debuggers either, just use printf or system.out.println, or whatever.
</p></div></div><p>
Using a debugger saves you a lot of time. if you consider yourself a coder, learn how to use a debugger. The 2 hours spent learning the basics of gdb (or the 0.5hours if you&#39;re using a debugger with a modern frontend) will be nothing in comparison to the time saved looking for a bug.</p><p>Learn to use your tools. For a c/c++ coder these tools are:<br />editor<br />compiler<br />debugger
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (spellcaster)</author>
		<pubDate>Sat, 26 May 2007 22:25:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Without Valgrind, mine and BAF&#39;s TINS &#39;07 entry would never have been submitted. It&#39;s just that good.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CGamesPlay)</author>
		<pubDate>Sat, 26 May 2007 22:29:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>A debugger is to programming as God-mode is to gaming.  <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /></p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
the 2 hours spent learning the basics of gdb
</p></div></div><p>
Dev-C++ comes with gdb all ready to go. You just have to click a few buttons in the IDE. Still, I prefer only to enable God-mode when absolutely necessary <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (james_lohr)</author>
		<pubDate>Sun, 27 May 2007 00:19:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
MSVC&#39;s debugger is handy, it useful catches some bound errors and uninitialised variables. The only problem I&#39;ve found is that it really slows down when doing even a few new objects using a STL list container.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Richard Phipps)</author>
		<pubDate>Sun, 27 May 2007 00:28:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
A debugger is to programming as God-mode is to gaming.
</p></div></div><p>
In that case I recommend that you code using copy con. Those fancy editors are pretty close to cheating either, eh?</p><p>I hope you meant this as a joke. If not, I hope you don&#39;t consider a job where you have to code or interact with coders.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (spellcaster)</author>
		<pubDate>Sun, 27 May 2007 00:29:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
A debugger is to programming as God-mode is to gaming. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div></div><p>
I rarely use debuggers, I use logfiles and I watch all the important variables using text_printf_ex instead. Is something wrong with me? <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Paul whoknows)</author>
		<pubDate>Sun, 27 May 2007 01:04:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Is something wrong with me?
</p></div></div><p>Not until you start working on large projects. Seriously, after a few days wasted debugging like that you will invest the time to learn a debugger.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CGamesPlay)</author>
		<pubDate>Sun, 27 May 2007 01:12:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok, I&#39;ll start right now.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Paul whoknows)</author>
		<pubDate>Sun, 27 May 2007 01:20:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I hope you meant this as a joke. If not, I hope you don&#39;t consider a job where you have to code or interact with coders.
</p></div></div><p>

Of course I was only teasing. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> </p><p>There are plenty of things you simply can&#39;t identify without a debugger, no matter how badly you pollute your code with log messages.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (james_lohr)</author>
		<pubDate>Sun, 27 May 2007 01:50:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I first started using gdb to quickly debug crashes:</p><p>1) Compile your code with the -ggdb option</p><p>2) Use &quot;gdb myprogram.exe&quot; to debug it</p><p>3) Use the gdb &quot;run&quot; command to start your program. You can enter any command line arguments here. &quot;run -res 640x480&quot;</p><p>4) Use the &quot;backtrace&quot; command to figure out where the crash occurred. This will tell you the line number of the crash, where this function was called from, and where the calling function was called from, and so on all the way to your main program.</p><p>There are plenty of other options that you can find using the &quot;help&quot; command, but these simple steps have alone have saved me countless hours of time.</p><p>I find that no bug can withstand the combined might of good coding style and gdb.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Myrdos)</author>
		<pubDate>Sun, 27 May 2007 02:14:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
There are plenty of other options that you can find using the help command, but these simple steps have alone have saved me countless hours of time.
</p></div></div><p>

After learning to use that, the next step should be learning how to use bt (backtrace), up, down and print together. After learning those, you&#39;ll be able to nail 99% of all bugs in no time.</p><p>For your problem, all you have to do is type &#39;tbreak &lt;filename&gt;:&lt;linenumber&gt;&#39;, with filename:line set to somewhere where the variable that is randomly changing is in scope - this will make the program stop <i>once</i> when it reaches that point. Run the program until it stops. </p><p>Then, type &#39;watch &lt;name_of_the_variable&gt;&#39; and the program will stop whenever the value gets changed. </p><p>You can use &#39;cont&#39; to continue if it&#39;s not the overwrite you were looking for (that is, it&#39;s happening inside the Set() method, which you can check with the &#39;bt&#39; command).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Jakub Wasilewski)</author>
		<pubDate>Sun, 27 May 2007 02:16:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><a href="http://www.dirac.org/linux/gdb/">Here&#39;s a tute,</a> I have a wierd little bug in my compiler/parser to practice on too...</p><p><img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=":D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (nonnus29)</author>
		<pubDate>Sun, 27 May 2007 04:39:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Are you using any sort of multi-threading?
</p></div></div><p>
No. It&#39;s a little difficult to rip it apart though; lots of classes that talk to each other and make isolating large chunks of code impractical.
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Dev-C++ comes with gdb all ready to go.
</p></div></div><p>
And that&#39;s the only nice thing you&#39;ll ever see me say about it. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><p>And yes, like I said it&#39;s to my shame I never really learned a debugger. I did try GDB a long time ago but never really got it working well. I still think this bug will just go away once the code&#39;s all cleaned up, but nonnus posted a nice looking link; guess I owe it to myself to read up. Or maybe look into Fortify.</p><p>Shame there isn&#39;t a site like the GotW for debuggers. Here&#39;s some source code for a simple program, here&#39;s a weird bug in the program, find the bug and fix it. Little exercises like that for noobs like me. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Sun, 27 May 2007 05:37:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I had to hack at Fortify to get it to even compile under mingw. After I did, though, it worked well.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Sun, 27 May 2007 07:55:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You can download a pdf manual for gdb here:<br /><a href="http://www.gnu.org/software/gdb/documentation/">http://www.gnu.org/software/gdb/documentation/</a><br />And download the latest version here:<br /><a href="http://www.gnu.org/software/gdb/download/">http://www.gnu.org/software/gdb/download/</a></p><p>I think these commands could spot your problem right away.<br />cmd-&gt;gdb filename.exe<br />1. Set a breakpoint at the beginning of your main function.<br />gdb-&gt;break filename.srclanguage:line_number<br />2. When you reach that breakpoint , set a watchpoint on your mystery variable<br />gdb-&gt;rwatch mystery_variable<br />3. Then set a condition on that breakpoint(rwatch is also a breakpoint) to notify<br />  you when your variable has reached a certain value.
</p><ol><li><p>is the breakpoint number of your rwatch breakpoint
</p></li></ol><p>gdb-&gt;condition # mystery_variable == 0</p><p>This will stop the program as soon as mystery_variable becomes 0.<br />Then use:<br />gdb-&gt;bt full</p><p>This should tell you more than enough to fix your program.</p><p><img src="http://www.allegro.cc/forums/smileys/cool.gif" alt="8-)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sun, 27 May 2007 10:08:44 +0000</pubDate>
	</item>
</rss>
