여기 에서 보고 링크를 따라가서...
Gunnar Kudrjavets Blog 에서 아티클을 봤다....
나도 역시나
#define SAFE_DELETE(pObject) if (pObject) {delete pObject; pObject = NULL;}
이런 매크로를 사용하고 있었다.
그런데.. NULL 을 delete 해도 괜찮다니..
역시나 의심을 안할 수 없었다.
바로 VC6.0 을 켜서 간단한 코드를 만들었다.
char* p = NULL;
printf("before delete p
");
delete p;
printf("after delete p
");
왠걸... 안전하게 종료한다.
이럴수가... 괜한 if 문으로 코드를 낭비하다니...
"
The C++ language guarantees that delete p will do nothing if p is equal to NULL. Since you might get the test backwards, and since most testing methodologies force you to explicitly test every branch point, you should not put in the redundant if test.
"
C++ 이 gurantee 한다니..
이제부터 나의 코드엔 SAFE_DELETE 는 없어지리라...
역시 사람은 많이 알고 봐야한다. -.-;;