글
Technical Article/펌 2004. 6. 24. 00:42C++ delete쓸때 NULL체크 하지말자!!!
[16.7] Do I need to check for NULL before delete p?
No!
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.
Wrong:
if (p != NULL)
delete p;
Right:
delete p;
http://www.parashift.com/c++-faq-lite/freestore-mgmt.html#faq-16.7
단, 클래스에서 new delete를 재정의해야만 쓸수있는 Brew같은 플랫폼에서는 NULL체크를 해주어야 된다.
delete 오버라이딩할때 널체크를 해줘서 널체크를 빼 주는것도 나쁘지 않을듯...
p.s 예전에 올렸던건데 혹시나 아직 못보신 분들을 위해서...
No!
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.
Wrong:
if (p != NULL)
delete p;
Right:
delete p;
http://www.parashift.com/c++-faq-lite/freestore-mgmt.html#faq-16.7
단, 클래스에서 new delete를 재정의해야만 쓸수있는 Brew같은 플랫폼에서는 NULL체크를 해주어야 된다.
delete 오버라이딩할때 널체크를 해줘서 널체크를 빼 주는것도 나쁘지 않을듯...
p.s 예전에 올렸던건데 혹시나 아직 못보신 분들을 위해서...
![](https://lh3.googleusercontent.com/-hYZb_novCPQ/V5HuGPkGFUI/AAAAAAAAANk/f8zcKkeTBbA1A-W6yuqfk12fs8bd8FeOQCL0B/banner_468_60.png)
RECENT COMMENT