10-05-2018 10:29 AM
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)?
Solved! Go to Solution.
10-08-2018 03:12 PM
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!
10-09-2018 07:07 AM
Excellent! Thank you for the for the information Francine.
John