10-12-2017 11:48 PM
Using, e.g., this simple example
#include <ansi_c.h>
static int i = 0;
for ( i = 0;
i < 1000000;
i ++ )
printf ("i: %d\n", i );
I am unable to stop program execution in the Interactive Window using the "Terminate Execution" button.
(CVI2017)
Solved! Go to Solution.
10-13-2017 09:03 AM
This looks like a race condition between active windows. Every time you call printf(), the default behavior is to make stdio the active window. In your code snippet, i think this is happening so fast that CVI doesn't actually get the buttonclick because it is no longer the active window.
Both of these modifications to your code snippet support my theory:
#include <ansi_c.h> #include <utility.h> static int i = 0; for ( i = 0; i < 10000; i ++ ){ printf ("i: %d\n", i ); Delay(.05); //gotta be quick! }
#include <ansi_c.h> #include <utility.h> static int i = 0; SetStdioWindowOptions(10000,0,0); for ( i = 0; i < 10000; i ++ ){ printf ("i: %d\n", i ); }
You can also use DebugPrintf() instead and the CVI window remains active.
I could file a CAR about this, but realistically I don't know how much we can do about it.
I'd rather have the current behavior that either of those.
~Trent
10-13-2017 09:40 AM
Thanks Trent! Yes I agree with you, it is the same problem if the code is run from within CVI and thus has nothing to do with the Interactive Window.
But now: why does
#include <ansi_c.h>
#include <utility.h>
static int i = 0;
for ( i = 0;
i < 10000;
i ++ ){
DebugPrint ("i: %d\n", i );
}
give the build error
7, 1 error: implicit declaration of function 'DebugPrint'. Make sure that you include the function prototype.
whereas your example works well - both functions Delay and DebugPrintf need utility.h?
10-13-2017 09:44 AM
Yes, both of those functions need utility.h. I think that build error is because you're missing the 'f' in DebugPrintf:
@Wolfgang wrote:
...
#include <ansi_c.h>
#include <utility.h>
static int i = 0;
for ( i = 0;
i < 10000;
i ++ ){
DebugPrint ("i: %d\n", i );
}
10-13-2017 10:16 AM
OK, now problem is solved, thanks again! I guess I will tell students to use DebugPrintf instead of printf to avoid this kind of problem.