Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to see global variable in certain C file, value seems to reset
    primarykey
    data
    text
    <p>I have a very frustrating bug that others on the team can't reproduce. I have tried cleaning the project, wiping the directory, pulling from the repository, rebuilding, and even testing in VS 2013.</p> <p>Background: a.c, b.c, c.c and b.inc are all compiled into a DLL (assume they are externed). <code>setfoo()</code> is called first from managed code. So far so good.</p> <p>Later on, <code>testfoo()</code> is called. The global variable is fine, there are no issues. Then <code>testfoo2()</code> is called. This is where things get interesting. I have the memory debugger on with <code>foo's</code> address, and it <strong>will read 4 in memory</strong>. However, if you hover over code in visual studio, it returns 0!. Also, it will output 0. There are many global variables (including <code>FILE</code> handles and they are reset to zero(causing nasty ASSERT failures), ONLY in c.c, but are fine when inspected with the debugger). There are many other x.c modules with that include that have no issues.</p> <p>Ok, now <code>testfoo()</code> is called again. Everything is fine in b.c world. The scary part is that the issue happens on only on my workstation! Any clues on how to debug this?</p> <p>This is from my memory, I believe the code is very close to this skeleton:</p> <p><strong>b.inc</strong></p> <pre><code>int foo; </code></pre> <p><strong>a.c</strong></p> <pre><code>#include &lt;b.inc&gt; void setfoo(){ foo = 4; } </code></pre> <p><strong>b.c</strong></p> <pre><code>#include &lt;b.inc&gt; void testfoo(){ printf(foo); //works } </code></pre> <p><strong>c.c</strong></p> <pre><code>#include &lt;b.inc&gt; void testfoo2(){ printf(foo); //foo is now 0 } </code></pre> <p>To Add: This is very complex, legacy code (think 70s), in a very large company and not much can be changed. There are thousands of variables that would be affected if we start adding extern. Also, I tried extern on one variable, and it still has an issue with that file.</p> <p><strong>I left out one tidbit. 'testfoo2()' launches in a managed thread.</strong> Again, this seems to be related to my machine, could be some setting in visual studio, dunno at this point, we want to just re-image the box. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload