Walt Mankowski wrote:

Isn't it just the C++ way of doing this:

  (int) 0

There are 4 ways of doing "this" in C++: reinterpret_cast, static_cast, dynamic_cast and const_cast. Now, const_cast can only cast away cv qualifiers (const and volatile). dynamic_cast uses RTTI for the casting, which means that it won't downcast a pointer to the wrong derived type, and has a chance of working with virtual inheritance. static_cast works according to the statically known type info, ignoring dynamic type info, and won't cast away cv qualifiers. I think. Now, the question is, and I really mean "the question" because I don't know the answer: what does reinterpret_cast do? I think it's supposed to be for "reinterpreting the bits of x having type A as if it really had the type B", but I'm pretty sure it's more complicated than that. I only used it once to pass parameters to an asm macro and then it stopped working upon a compiler upgrade and I changed the spelling to C-like and it worked.


Not sure why you'd ever need to do that, mind you...


Macro expansion or template instantiation or code generation or whatever results in all kinds of corner cases. It's nice when int a[]={1,2,}; compiles although a human probably wouldn't insert that last comma, for example. And then the error message in the reinterpret_cast case is utterly ridicuous.

Reply via email to