From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Debugger & global **variable

Solved!
Go to solution

While working through some code examples in the book "21st Century C, 2nd Edition", using LabWindows/CVI 2017, I stumbled upon an interaction between the CVI debugger and globally declared pointers to pointers variables (**variable) that I don't understand.  Below is a snippet of code that will replicate the observed behavior:

#include <stdio.h>
// Declare and initialize a global string array:
char **stringArray = (char* []) {"One", "Two", "Three"};

int main ()
{
	for (int i=0; i<3; i++) 
		printf("Item %d: %s\n", i, stringArray[i]);
	
	getchar(); // Allow the user to see the standard IO window
}

When the above code is built and run with the 32-bit debug configuration, with the Debugging Level set to "No run-time checking", the code outputs as expected:

Item 0: One
Item 1: Two
Item 2: Three

 When run with the Debugging Level set to "Standard", the following error occurs:

NON-FATAL RUN-TIME ERROR:   "StringArray.c", line 9, col 36, thread id 11656:   Pointer is invalid.

So my questions are:

1.) Why does debugger throw this error on code that functions properly?

2.) Is there any way to selectively tell the debugger to ignore sections of code during runtime checking (e.g. with DEFINE's)?

 

 

 

0 Kudos
Message 1 of 3
(1,990 Views)
Solution
Accepted by topic author JSnyder

Unlike the "No run-time checking" option, "Standard" debugging includes protection from run-time memory errors (more information here). The error you're receiving is non-fatal, so it's more of a warning and execution of the code can still continue. This specific error is a pointer arithmetic error which can be caused by a variety of reasons, and you can find more information about it here.

 

Rather than ignoring debugging for certain sections of code, I'd recommend filtering the errors so only fatal errors are displayed. You can do so by following the instructions in the document below:

Preventing Non-Fatal Run-Time Errors From Being Displayed In LabWindows/CVI

 

Hope this helps!

 

Francine P.
Applications Engineering
National Instruments
Message 2 of 3
(1,943 Views)

Excellent!  Thank you for the for the information Francine.

 

John

0 Kudos
Message 3 of 3
(1,931 Views)