|
질문드림 님이 쓰신 글 :
: char *buf=0;
: //buf = (char *) calloc( 20, sizeof(char) );
: _ASSERT( buf != NULL );
: strcpy( buf, "Hello, World" );
: free( buf );
:
: 이라고 해서 프로그램을 실행 시켜보면 Access Violation이 발생합니다.
:
_ASSERT, _ASSERTE Macros
Evaluate an expression and generate a debug report when the result is FALSE (debug version only).
위의 설명과 같이 ()의 연산이 false면 Access Violation이 발생됩니다.
_ASSERT( buf != NULL ); --> if (buf == NULL), generate a debug report
주석을 푸시면 정상일겁니다.
<아래글도 추가로 읽어보시고 참고하시길..>
The _ASSERT and _ASSERTE macros provide an application with a clean and simple mechanism for checking assumptions during the debugging process. They are very flexible because they do not need to be enclosed in #ifdef statements to prevent them from being called in a retail build of an application. This flexibility is achieved by using the _DEBUG macro. _ASSERT and _ASSERTE are only available when _DEBUG is defined. When _DEBUG is not defined, calls to these macros are removed during preprocessing.
_ASSERT and _ASSERTE evaluate their booleanExpression argument and when the result is FALSE (0), they print a diagnostic message and call _CrtDbgReport to generate a debug report. The _ASSERT macro prints a simple diagnostic message, while _ASSERTE includes a string representation of the failed expression in the message. These macros do nothing when booleanExpression evaluates to nonzero.
Because the _ASSERTE macro specifies the failed expression in the generated report, it enables users to identify the problem without referring to the application source code. However, a disadvantage exists in that every expression evaluated by _ASSERTE must be included in the debug version of your application as a string constant. Therefore, if a large number of calls are made to _ASSERTE, these expressions can take up a significant amount of space.
|