|
C++빌더에서 조건이 거짓이 되는 경우 메시지창이 뜨게 하려면
#include <assert.h>
를 하시고,
char *buf=0;
//buf = (char *) calloc( 20, sizeof(char) );
assert( buf != NULL );
strcpy( buf, "Hello, World" );
free( buf );
와 같이 사용하시면 됩니다.
또는 자료실에 디버깅을 위한 ASSERT가 있으니
그것을 사용해도 됩니다. 보다 자세한 조건 검사 메시지가 나옵니다.
_ASSERT 를 사용했을때 Access Violation 에러가 나오는 것은 매크로에 약간의 이상이 있어서입니다.
_ASSERT는 사용하지 마시기 바랍니다.
그럼..
질문드림 님이 쓰신 글 :
: char *buf=0;
: //buf = (char *) calloc( 20, sizeof(char) );
: _ASSERT( buf != NULL );
: strcpy( buf, "Hello, World" );
: free( buf );
:
: vc++ 에서 실행하면 메시지 창이 발생하는데,
: c빌더에서 실행하면 Access Violation이 발생해서 질문드렸습니다.
: vc++와 같은 ASSERT관련 메시지 창이 떠야 정상이 아닌지 싶어 질문드립니다.
:
:
: 권혁균 님이 쓰신 글 :
: : 질문드림 님이 쓰신 글 :
: : : 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.
|