4 ms·
> And it was never guaranteed that NULL (which is a macro) expands to just plain 0. True, but is was guaranteed that NULL expands to “an implementation-define
by kps 8y ago
> And it was never guaranteed that NULL (which is a macro) expands to just plain 0.
True, but is was guaranteed that NULL expands to “an implementation-defined C++ null pointer constant” (C++98 §18.1), where a ‘null pointer constant’ is “an integral constant expression (5.19) rvalue of integer type that evaluates to zero" (C++98 §4.10). So while it didn't have to be just plain (literal) 0, it did have to be a compile-time constant integer 0, which is otherwise just as good unless you're doing macro magic.
(This differed from C (ANSI era), in which a null pointer constant can alternatively have type (void*), and often does.)
The fact that a pure declaration requires a literal single character ‘0’ (rather than 0) is just one sad example of C++'s ad-hoc irregular overloading of things to mean different things.
- int_19h 8y agoIt may be ad-hoc (although I would argue that "0" in this case is really just a token that's a part of syntax - basically a numerical keyword - so expecting a constant expression is too much). But, in any case, the main point is that it never changed - it was always wrong to use =NULL to denote abstract virtual methods, and there were always implementations that broke that. So it's a strange example of the lack of stability in C++.