Quantcast
Channel: LabWindows/CVI topics
Viewing all articles
Browse latest Browse all 5339

return statement gives error

$
0
0

 

#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 thereturn 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.


Viewing all articles
Browse latest Browse all 5339

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>