Noah said:
That cast is invalid and, luckily, unnecissary.
Later in the thread you attempt to deny that you wrote
this statement....
The above cast is definitely valid.
You can't static_cast between unrelated types. An int and a T* are
totally unrelated.
You can static_cast in any situation where there is an implicit
conversion from source to destination.
Here's another example:
struct A { };
struct B { operator A() { return A(); } };
int main() { static_cast<A>(b); }
Classes A and B are unrelated but the static_cast is good.
Luckily enough, 0 is magic in that it can be any
pointer as well as an integral.
0 cannot be a pointer. 0 is an integer.
So, that is just calling a static cast from T* to T*
It is a static cast from the integer constant 0 to a pointer to T.
There is an implicit conversion defined from integral constants
of value 0 (also known as null-pointer constants), to pointers.
...if it wasn't the code would not compile.
Nonsense, the code is fine.
What the original coder probably intended was a reinterpret cast.
He certainly did not intend that, as a reinterpret cast would not
generate a null pointer in the case where null pointers are not
all-bits-zero. I hate to think what it would do in the case where
the pointer has more bits than an integer.
However, since the static cast worked it shows that it is not
necissary to perform any casting at all.
You just said that the code would not compile without the
static cast, now you say that the cast is not necessary.