Berkeley CSUA MOTD:2014:January:14 Tuesday
Berkeley CSUA MOTD
2014/1/14-2/5 [Computer/SW/Languages/C_Cplusplus] UID:54763 Activity:nil
1/14    Why is NULL defined to be "0" in C++ instead of "((void *) 0)" like in
        C?  I have some overloaded functtions where one takes an integer
        parameter and the other a pointer parameter.  When I call it with
        "NULL", the compiler matches it with the integer version instead of
        the pointer version which is a problem.  Other funny effect is that
        sizeof(NULL) is different from sizeof(myPtr).  Thanks.
        \_ In C, a void pointer is implicitly convertable to any other pointer
           type, so (void *)0 works in any context where you need a pointer.
           C++ doesn't allow that conversion, because it isn't typesafe.
           (That's why you can write "int *p = malloc(4)" in C but not in C++.)
           Unfortunately, there's no simple equivalent of (void *)0 that works
           in C++.  Recent C++ compilers have added a new keyword "nullptr"
           that does the right thing, but they've avoided defining NULL to it
           so they don't break old code.  --mconst
Berkeley CSUA MOTD:2014:January:14 Tuesday