4 ms·
If you think a C++ compiler has the option to define NULL as ((void * ) 0) then all I ask is that you simply try it yourself and let me know what compiler error
by mpyne 14y ago
If you think a C++ compiler has the option to define NULL as ((void * ) 0) then all I ask is that you simply try it yourself and let me know what compiler error you get. Make sure to turn off permissive flags.
class Foo { };
int main() {
Foo *foo = malloc(sizeof(Foo)); // returns void*
}
- cjensen 14y agoYou are confusing the preprocessor #define named NULL with the null pointer. Your code example involves void pointers, which is yet a third thing.
- mpyne 14y agoThat's because NULL is the pre-processor define. The null pointer itself has no name in C or C++ (pre-11), except that the language will convert integer '0' into whatever the hardware's null pointer is (usually also 0) when converting integral types to pointer types. C++11 added a name and specific type for the null pointer but that's about it.