Checking for null before pointer usage

后端 未结 13 2641
孤独总比滥情好
孤独总比滥情好 2021-02-20 09:32

Most people use pointers like this...

if ( p != NULL ) {
  DoWhateverWithP();
}

However, if the pointer is null for whatever reason, the functi

13条回答
  •  遇见更好的自我
    2021-02-20 10:08

    I think I've seen more of. This way you don't proceed if you know it's going to blow up anyway.

    if (NULL == p)
    {
      goto FunctionExit; // or some other common label to exit the function.
    }
    

提交回复
热议问题