블로그 이미지
fiadot_old

칼퇴근을 위한 게임 서버 개발 방법론에 대한 심도있는 고찰 및 성찰을 위한 블로그!

Rss feed Tistory
Technical Article/펌 2004. 6. 24. 00:42

C++ 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 예전에 올렸던건데 혹시나 아직 못보신 분들을 위해서...
,
TOTAL TODAY