|
Null Pointers and Delete
C++ guarantees that operator delete checks its argument for null-ness. If the argument is 0, the delete expression has no effect. In other words, deleting a null pointer is a safe (yet useless) operation. There is no need to check the pointer for null-ness before passing it to delete:
if (p) // useless; delete already checks for a null value
delete(p);
위의 내용으로 봐서도 검사가 필요없이 사용하셔도 됩니다.
내부적으로 Null인지를 확인한다고 합니다.
건승을 빕니다.
수야!╋ 님이 쓰신 글 :
: char *s = NULL;
: delete s;
:
: 위 문장은 에러가 발생되지 않는군요 ( 빌더나 VC에서도요... )
:
: 많은 기간동안 NULL이 아닌놈을 지우기 위해서 발악해 왔습니다.
:
: 그런데 혼돈이 생겼네요.. -_-;
:
: #define SAFE_DELETE( x ) if( x ) delete x; x = NULL;
:
: 이렇게 선언하고 사용했는데
:
: 혼돈이 생겼습니다.
:
: if 문을 빼버려야하는 고민이 생겼거든요...
:
: delete가 하는 일을 알고 싶습니다.
:
: MSDN이나 빌더의 헬프를 찾아봐도 나오지 않는군요... 못찾은 걸지도..
:
: 프로그램을 하던 당시와 함께 당연하다 생각하던 널의 delete는 에러다 라는 ....
:
: 알려주세요~ ㅠ.ㅠ
|