Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>The reinterpret_cast as we know can cast any non-standard pointer to another non-standard pointer.</p> </blockquote> <p>Almost, but not exactly. For example, you can't use reinterpret_cast to cast a <code>const int*</code> to an <code>int*</code>. For that, you need <code>const_cast</code>.</p> <blockquote> <p>How does reinterpret_cast work, What is the magic(the internal implementation) that allows reinterpret_cast to work?</p> </blockquote> <p>There's no magic at all. Ultimately, all data is just bytes. The C++ type system is merely an abstraction layer which tells the compiler how to "interpret" each byte. A <code>reinterpret_cast</code> is similar to a plain C-cast, in that it simply says "to hell with the type system: interpret these bytes as type X instead of type Y!"</p> <blockquote> <p>How to ensure safety when using reinterpret_cast? As far as i know, it doesn't guarantee of safe casting, So what precaution to take while using reinterpret_cast?</p> </blockquote> <p>Well, <code>reinterpret_cast</code> is inherently dangerous. You shouldn't use it unless you really know what you're doing. Try to use <code>static_cast</code> instead. The C++ type system will protect you from doing anything too dangerous if you use <code>static_cast</code>.</p> <blockquote> <p>What is the practical usage of this operator. I have not really encountered it in my professional programing experience, wherein I could'nt get around without using this operator.Any practical examples apart from usual int* to char* will be highly helpful and appreciated.</p> </blockquote> <p>It has many uses, but usually these uses are somewhat "advanced". For example, if you are creating a memory pool of linked blocks, and storing pointers to free blocks on the blocks themselves, you'll need to <code>reinterpret_cast</code> a block from a <code>T*</code> to a <code>T**</code> to interpret the block as a pointer to the next block, rather than a block itself.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload