I'm getting different output from Debug and Release builds. The former
appears more likely to be correct (it's not too obvious, because this
program is doing lots of complicated floating point calculations)

My first guess would be that there is uninitialized variable access.
Is it possible to automatically detect it in Debug mode?

P.S. I'm using Visual Studio 2005 Standard

Re: detecting uninitialized variable access? by Alex

Alex
Sun Dec 09 05:41:31 PST 2007

<n.torrey.pines@gmail.com> wrote:
> My first guess would be that there is uninitialized
> variable access.
> Is it possible to automatically detect it in Debug mode?
>
> P.S. I'm using Visual Studio 2005 Standard

You can compile your code with warning level 4. It should
emit C4700 warning if uninitialized variable is used.

HTH
Alex



VC++ is incredibly indeterminate. by Jeff_Relf

Jeff_Relf
Sun Dec 09 10:33:14 PST 2007

You ( n_torrey_pines ) say your Release-Build might have bugs,

Turn off optimizations, see that that does.
If it helps, you might have â?? Sequence-Point â?? issues.

In other words, for the sake of so-called â?? optimizations â??,
VC++ is incredibly indeterminate.

Personally, I use only one build mode:
My â?? Visual C++ Compiler Options â??:

â?? /Ob2 /Oi /FD /MT /GS- /GR- /Fo"EXE\\"
/Fd"EXE\vc80.pdb" /W4 /WX /nologo /c /Zi /TP â??.

Linker:
â?? /OUT:"EXE/X.EXE" /NOLOGO /MANIFEST:NO /DEBUG /SUBSYSTEM:WINDOWS
/OPT:REF /OPT:NOICF /OPT:NOWIN98 /MACHINE:X86 /ERRORREPORT:PROMPT
kernel32.lib ..... â??.


Re: detecting uninitialized variable access? by n

n
Sun Dec 09 13:28:53 PST 2007

On Dec 9, 5:41 am, "Alex Blekhman" <tkfx.REM...@yahoo.com> wrote:
> <n.torrey.pi...@gmail.com> wrote:
> > My first guess would be that there is uninitialized
> > variable access.
> > Is it possible to automatically detect it in Debug mode?
>
> > P.S. I'm using Visual Studio 2005 Standard
>
> You can compile your code with warning level 4. It should
> emit C4700 warning if uninitialized variable is used.

I don't think this could have caught my bug. This flooded me with
warnings, mostly about Boost libraries I use.

I found the bug after several hours of incrementally augmenting the
code with print statements, rerunning the program, comparing Release
and Debug outputs, etc.

It turned out to be the opposite of an of-by-one error: I was leaving
the diagonal elements of a triangular matrix uninitialized.

If the debugger could detect access to uninitialized values, this time-
consuming process of inserting print statements could have been
avoided. I wonder if there are other C++ compilers that can do that,
but AFAIK VC++ is actually the best one for debugging, sadly.

Re: detecting uninitialized variable access? by nathan

nathan
Sun Dec 09 15:08:53 PST 2007

In article <d267f5ad-8ece-4b0b-b328-e9608efa61f4@t1g2000pra.googlegroups.com>,
<n.torrey.pines@gmail.com> wrote:
>If the debugger could detect access to uninitialized values, this
>time-consuming process of inserting print statements could have
>been avoided. I wonder if there are other C++ compilers that can do
>that, but AFAIK VC++ is actually the best one for debugging, sadly.

DevStudio 2005 can detect use of uninitialized *local* variables.
Can't do it with allocated memory. If you want to detect such errors
in allocated memory, you'll need a 3rd party app like Boundschecker
(see http://www.compuware.com/products/devpartner/visualc.htm ), or
Valgrind (Linux only, see http://valgrind.org/ ). Boundschecker is
fairly pricey, and last time I used it (some years ago), it slowed
program execution down to a crawl. Maybe it's improved in the past few
years on either/both fronts.

Nathan Mates

--
<*> Nathan Mates - personal webpage http://www.visi.com/~nathan/
# Programmer at Pandemic Studios -- http://www.pandemicstudios.com/
# NOT speaking for Pandemic Studios. "Care not what the neighbors
# think. What are the facts, and to how many decimal places?" -R.A. Heinlein