10-14-2016 01:47 PM
#define OPEN 0
#define CLOSE 1
#define BITMAP 2
void CreateFiles (int state) { if (state == OPEN) { DoStuff(); } if (state == BITMAP) { DoDifferentStuffAnd(); return; } if (state == CLOSE) { CloseFile (x); CopyFile (x,y); } } // Create Files
I have the code above. When executing, say the value OPEN is passed to the state variable. DoStuff() executes fine, and the program moves on to check the BITMAP and CLOSE statements.
The BITMAP statement checks as false, the program jumps out of that if, and moves on to the CLOSE statement.
When checking the CLOSE statement however (which is false) the program jumps into the if statement braces as if it were true, but it skips past the first function CloseFile() and executes the second function CopyFile() .
If I get rid of the return in the BITMAP chunk, it executes as it should and jumps out of the CLOSE statement properly.
If I add the return back into the BITMAP chunk above it, it again jumps into the CLOSE chunk upon execution (even though it's false), skipping the first line and executing the second line.
Anybody know what's going on here? It works fine if I put the CLOSE chunk before the BITMAP chunk which is an easy fix, but I need to understand this. Was lucky to find the error before the app went live.
Solved! Go to Solution.
10-16-2016 09:15 AM
Hi,
If that happened to me; first thing that would come to my mind would be that my code and my debugged process are of different versions. So I would try a clean build (delete all files/folders generated during build, just leave the code and libraries and try again)?
This also happens when I remote debug my code and forget to copy the final executable/DLL/etc to the target machine.
Are you debugging your code remotely?
This means, the actual execution is not happening as what it looks like, but since debugged process is not the exact representation of the code they simply do not syncronise.
Please make sure that is not the case for you.
p.s: I would code this with 1 if and 2 else if blocks. Since state cannot be equal to more than one named states.
10-17-2016 07:18 AM - edited 10-17-2016 07:19 AM
Thanks ebalci, some good ideas.
I think you may be onto something regarding the version mismatch. I had beeen getting a weird error about not being able to find the debug version, but I reset the locations in the Target Settings and the error went away.
There could be some residual effect happening, and a clean rebuild from scratch sounds like the right way to go. Will give it a try and report back.
10-17-2016 01:12 PM
Still doing it with a totally clean build, save, new file names, different location.
Going to change it to a switch statement, but thia problem is really bugging me.
Think I might open a service case unless someone from NI wants to chime in here.
10-18-2016 09:04 AM
Another possibility is that you have some serious memory corruption going on somewhere else in your program (although that probably wouldn't always happen the same way). A lost pointer... Do you have all warnings enabled and extended debug options enabled ? Pass your code through Valgrind ?
10-18-2016 09:20 AM
Hello Scot,
I could reproduce the issue with your code. While CopyFile() is higlighted, it doesn't seem to be executed though, so it's just a matter of how the debugger displays the current executed code.
I filled a bug, ID 610601 to track the issue.
Thanks for reporting this bug.
Constantin