In either C or C++, should I check pointer parameters against NULL/nullptr?

后端 未结 20 2330
有刺的猬
有刺的猬 2020-11-27 03:54

This question was inspired by this answer.

I\'ve always been of the philosophy that the callee is never responsible when the caller does something stupid, like passi

20条回答
  •  我在风中等你
    2020-11-27 04:36

    I think that you should strive to write code that is robust for every conceivable situation. Passing a NULL pointer to a function is very common; therefore, your code should check for it and deal with it, usually by returning an error value. Library functions should NOT crash an application.

提交回复
热议问题