" i = 10 " gives " i == 6 " ?!?!?!

  • Thread starter Thread starter Maarten
  • Start date Start date
M

Maarten

Hello,

I'm a software engineer for a Dutch company and I am
working on the improvement of a already made program and
I've found a very curious problem. It consists of two
parts, explained below:

When one of my functions is called, the program works as
it is supposed to do, but when I add a line, say for
example:
int i;
i = 10;
or something like that, the progam stops executing the
function before it reaches the end of its code. The more
lines of code I put in the function, the earlier the
function is stopped.

Almost stranger is the fact that when I place the code
above (int i; i = 10;) in the code and I use a debugger to
view the process, I can see the value of 'i' change from
i = 835xxxxxx at function start to
i = 12xxxxx somewhere in the function (where 'i' is not
called) to
i = 6 after the line 'i = 10;'

I myself truly haven't got a clue why this should happen.
Anybody who can help?

With kind regards,

Maarten
 
Hi,

Sounds like you're either debugging a release (and optimized) build, or the
source code you're debugging isn't the code that's running. Have you tried
deleting the build, then completely rebuilding a debug build? I'd be
suspicious, if you got the program from somewhere else, that there're some
dependencies that are wrong and so it's not compiling or linking the code
you're changing.

Thanks,

Steve
 
Do you see this behaviour only while you are stepping through in debug mode?

If yes, you could try to delete the .ncb file and recompile your project

José
 
Maarten said:
I'm a software engineer for a Dutch company and I am
working on the improvement of a already made program and
I've found a very curious problem. It consists of two
parts, explained below:

When one of my functions is called, the program works as
it is supposed to do, but when I add a line, say for
example:
int i;
i = 10;
or something like that, the progam stops executing the
function before it reaches the end of its code. The more
lines of code I put in the function, the earlier the
function is stopped.

Almost stranger is the fact that when I place the code
above (int i; i = 10;) in the code and I use a debugger to
view the process, I can see the value of 'i' change from
i = 835xxxxxx at function start to
i = 12xxxxx somewhere in the function (where 'i' is not
called) to
i = 6 after the line 'i = 10;'

I myself truly haven't got a clue why this should happen.
Anybody who can help?

Both of these point to the same cause: the compiled code you're running
isn't generated from the source code you're debugging. Check for any
deployment errors, try wiping old versions from the system etc.
 
So the problem lays with the debugger not usign the actual correct symbols
yet you encourage hiding the problem.

I'm not encouraging hiding the problem - I'm encouraging sorting the
problem out, at least in the short term, so that the OP can get on with
coding.
If the debugger is showing incorrect code with whats running in memory, any
reasonable person can see the bug is the debugger.

It's certainly a problem in the debugger or build tool (or possibly
file format for debug information, if it doesn't contain enough
information to verify that the code being executed is actually the code
that the debug information has been generated for). However, knowing
that isn't likely to help the OP. Knowing how to get back to a working
system *is* likely to help them.
 
So the problem lays with the debugger not usign the actual correct symbols
yet you encourage hiding the problem.

If the debugger is showing incorrect code with whats running in memory, any
reasonable person can see the bug is the debugger.
 
Thank you all for your help and early replies.
I believe that the problem is indeed, as some have said,
that the code that is running isn't the code that I'm
viewing/editing. To solve this, I've tried a few things:

I've tried deleting some old versions, but this didn't
help.
I've used the 'clean' function in Visual C++ to delete al
the build files, but this didn't help either.
I've removed al the .cpp, .h and recource-files form the
project and added the ones I wanted to use from the right
directory. This was ok, but for 2 files. These were the
files 'StdAfx.cpp' and 'StdAfx.h'. I believe that they are
generated by MSVisualStudio. But removing and adding the
other files didn't solve my problem.

Does anybody have any idea what else I can try?

Best regards,
Maarten Veldink
 
Maarten Veldink said:
Thank you all for your help and early replies.
I believe that the problem is indeed, as some have said,
that the code that is running isn't the code that I'm
viewing/editing. To solve this, I've tried a few things:

I've tried deleting some old versions, but this didn't
help.

That means you just haven't deleted the *right* old version :)

I suggest you get a process viewer which can show you exactly which
process is being run, and delete that one, then do a clean build.

The process viewer I use is from www.prcview.com.
I've used the 'clean' function in Visual C++ to delete al
the build files, but this didn't help either.
I've removed al the .cpp, .h and recource-files form the
project and added the ones I wanted to use from the right
directory. This was ok, but for 2 files. These were the
files 'StdAfx.cpp' and 'StdAfx.h'. I believe that they are
generated by MSVisualStudio. But removing and adding the
other files didn't solve my problem.

Does anybody have any idea what else I can try?

No, but then this doesn't sound like a very C#-related question - I
suggest you try on the managed C++ group.
 
Hello, Maarten!

In such case I usually just create a brand new project
and then replace the sourcecode of the new project
with the one I want to work with...

Hope that helps.

You wrote on Mon, 1 Mar 2004 03:08:30 -0800:

M> I'm a software engineer for a Dutch company and I am
M> working on the improvement of a already made program and
M> I've found a very curious problem. It consists of two
M> parts, explained below:

M> When one of my functions is called, the program works as
M> it is supposed to do, but when I add a line, say for
M> example:
M> int i;
M> i = 10;
M> or something like that, the progam stops executing the
M> function before it reaches the end of its code. The more
M> lines of code I put in the function, the earlier the
M> function is stopped.

M> Almost stranger is the fact that when I place the code
M> above (int i; i = 10;) in the code and I use a debugger to
M> view the process, I can see the value of 'i' change from
M> i = 835xxxxxx at function start to
M> i = 12xxxxx somewhere in the function (where 'i' is not
M> called) to
M> i = 6 after the line 'i = 10;'

M> I myself truly haven't got a clue why this should happen.
M> Anybody who can help?

M> With kind regards,


With best regards, Nurchi BECHED.
 
Back
Top