is return; the same as return NULL; in C++?
没有.
return用于从没有返回值的函数“中断”,即返回类型为void.
return NULL返回值NULL,并且找到的函数的返回类型必须与NULL兼容.
I understand that in C++, return NULL; is the same as return 0; in the context of pointers.
有点. NULL可能不等于0,但它至少会转换为.
Obviously for integers, this is not the case as NULL cannot be added, subtracted, etc.
您可以对指针执行加法和减法.但是,无论如何,NULL必须具有整数类型(在C 03中为4.10 / 1和18.1 / 4),因此它没有实际意义. NULL很可能是一个扩展为0或0UL的宏.
一些现代编译器至少会警告你,如果它实际上是你写的NULL.
And that it is encouraged by some to use 0 instead of NULL for pointers because it is more convenient for portability. I’m curious if this is another instance where an equivalence occurs.
不,我不同意这个建议.虽然我可以看到它的来源,但由于NULL的确切定义因实现而异,因此当切换到C 11时,使用NULL将更容易用nullptr替换,并且如果没有其他内容可以自我记录.