National Instruments 320685D-01 ユーザーズマニュアル

ページ / 211
Chapter 1
LabWindows/CVI Compiler
©
 National Instruments Corporation
1-13
LabWindows/CVI Programmer Reference Manual
This macro could be useful in the following situation: LabWindows/CVI reports erroneous 
run-time errors because you set a pointer to dynamic memory in a source module and you then 
resize it in an object module. The following steps describe how this error occurs: 
1.
You declare a pointer in a source module you compile with debugging enabled. You then 
assign to the pointer an address that 
malloc
 or 
calloc
 returns: 
AnyType *ptr;
ptr = malloc(N);
2.
You reallocate the pointer in an object module so that it points to the same location in 
memory as before. This might occur if you call the 
realloc
 function or free the pointer 
and then reassign it to memory that you allocate with 
malloc
:
ptr = realloc(ptr, M); /* M > N */
or
free(ptr);
ptr = malloc(M);
3.
You use the same pointer in a source module you compile with debugging enabled. At 
this point, LabWindows/CVI still expects the pointer to point to a block of memory of 
the original size 
(N)
.
*(ptr+(M-1))
/* This generates a fatal run-time error, */
/* even though it is a legal expression.  */
To prevent this error, use the 
DISABLE_RUNTIME_CHECKING
 macro to disable checking for 
the pointer after you allocate memory for it in the source module:
ptr = malloc(N);
DISABLE_RUNTIME_CHECKING(ptr);
Disabling Library Protection Errors for Functions
You can disable or enable library protection errors by placing pragmas in the source code. 
LabWindows/CVI ignores these pragmas when you compile without debugging information, 
that is, if the debugging level is None. For example, the following two pragmas enable and 
disable library checking for all the function declarations that occur after the pragma within a 
header or source file. The pragmas affect only the functions declared in the file in which the 
pragmas occur. These pragmas do not affect nested include files.
#pragma EnableLibraryRuntimeChecking 
#pragma DisableLibraryRuntimeChecking 
The following pragmas enable and disable library checking for a particular function. You 
must declare the function before the occurrence of the pragma.
#pragma EnableFunctionRuntimeChecking 
function
#pragma DisableFunctionRuntimeChecking 
function
 
00ProRef.book : 06chap01.fm  Page 13  Monday, March 9, 1998  3:23 PM