IT. Expert System.

C++

reinterpret_cast


Used to change one data type in a non-portable way. It is normally used to cast between incompatible pointer types.

Syntax:
reinterpret_cast < new_type > ( expression ) 

reinterpret_cast (object)


Example:

#include 
#include 
#include 
int f() { return 42; }
int main()
{
    int i = 7;
 
    // pointer to integer and back
    uintptr_t v1 = reinterpret_cast(&i); // static_cast is an error
    std::cout << "the value of &i is 0x" << std::hex << v1 << '\n';
    int* p1 = reinterpret_cast(v1);
    assert(p1 == &i);
 
    // pointer to function to another and back
    void(*fp1)() = reinterpret_cast(f);
    // fp1(); undefined behavior
    int(*fp2)() = reinterpret_cast(fp1);
    std::cout << std::dec << fp2() << '\n'; // safe
 
    // type aliasing through pointer
    char* p2 = reinterpret_cast(&i);
    if(p2[0] == '\x7')
        std::cout << "this system is little-endian\n";
    else
        std::cout << "this system is big-endian\n";
 
    // type aliasing through reference
    reinterpret_cast(i) = 42;
    std::cout << i << '\n';
}


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 288 / 158732959. Delta: 0.03253 с