labwindowsnullChk返回并返回一个错误



什么是nullChk,应该如何正确使用它?

我正在使用以下代码行:

nullChk(temp = malloc (numBytes + 1));  

然后我得到以下错误消息:

  700, 9    error: use of undeclared identifier 'error'
  700, 9    error: use of undeclared label 'Error'

看起来nullChk是一个宏。我在toolbox.h中找到了下面的定义和注释。注意列出的假设。如果你不想的话,你不必使用这个宏——我自己也觉得没必要。

/*  The errChk and nullChk macros are useful for implementing a consistent error
    handling system.  These can macros can be place around function calls to
    force an  automatic jump to a function's error handling code when an error 
    occurs.  This is analogous to exception handling, and is even easier to use.
    These macros make the following assumptions:
        1)  The following local declaration of an error code variable is
            made in every function in which they are used:
            int error = 0;
        2)  Every function in which they are used contains a goto label
            named Error which precedes the error handling code for the function.
        3)  Every function call or error code enclosed in a errChk() macro
            is assumed to return an integer which, if negative, is the code for
            the error which occured.  If the value is zero or positive then the
            error checking macros have no effect.
            Every function call or value enclosed in a nullChk() macro is
            assummed to return a non-zero value if no error occurred, or a
            zero value if an "Out Of Memory" error occurred (nullChk() is
            useful for malloc, calloc, and similar resource allocation functions).
*/
#ifndef errChk
#define errChk(fCall) if (error = (fCall), error < 0) 
{goto Error;} else
#endif
#ifndef nullChk
#define nullChk(fCall) if ((fCall) == 0) 
{error = UIEOutOfMemory; goto Error;} else
#endif

以上代码版权所有(c)National Instruments 1987-1996。保留所有权利

相关内容

  • 没有找到相关文章

最新更新