[expr.reinterpret.cast]

# 7 Expressions [[expr]](./#expr)

## 7.6 Compound expressions [[expr.compound]](expr.compound#expr.reinterpret.cast)

### 7.6.1 Postfix expressions [[expr.post]](expr.post#expr.reinterpret.cast)

#### 7.6.1.10 Reinterpret cast [expr.reinterpret.cast]

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L4880)

The result of the expression reinterpret_cast<T>(v) is the
result of converting the expression v to type T[.](#1.sentence-1)

If T is an lvalue reference type or an rvalue reference to function type, the result is an lvalue;
if T is an rvalue reference to object type, the result is an xvalue;
otherwise, the result is a prvalue and the[lvalue-to-rvalue](conv.lval "7.3.2 Lvalue-to-rvalue conversion [conv.lval]"), [array-to-pointer](conv.array "7.3.3 Array-to-pointer conversion [conv.array]"),
and [function-to-pointer](conv.func "7.3.4 Function-to-pointer conversion [conv.func]") standard conversions are
performed on the expression v[.](#1.sentence-2)

Conversions that can be performed explicitly
using reinterpret_cast are listed below[.](#1.sentence-3)

No other conversion can
be performed explicitly using reinterpret_cast[.](#1.sentence-4)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L4896)

The reinterpret_cast operator shall not cast away constness ([[expr.const.cast]](expr.const.cast "7.6.1.11 Const cast"))[.](#2.sentence-1)

An expression of integral, enumeration, pointer, or pointer-to-member type
can be explicitly converted to its own type; such a cast yields the value of
its operand[.](#2.sentence-2)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L4902)

[*Note [1](#note-1)*:

The mapping performed by reinterpret_cast might, or might not, produce a
representation different from the original value[.](#3.sentence-1)

â *end note*]

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L4908)

A pointer can be explicitly converted to any integral type large enough
to hold all values of its type[.](#4.sentence-1)

The mapping function is implementation-defined[.](#4.sentence-2)

[*Note [2](#note-2)*:

It is intended to be unsurprising to those who know the addressing
structure of the underlying machine[.](#4.sentence-3)

â *end note*]

A value of type std​::​nullptr_t can be converted to an integral
type; the conversion has the same meaning and validity as a conversion of(void*)0 to the integral type[.](#4.sentence-4)

[*Note [3](#note-3)*:

A reinterpret_cast cannot be used to convert a value of any type to the typestd​::​nullptr_t[.](#4.sentence-5)

â *end note*]

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L4928)

A value of integral type or enumeration type can be explicitly converted
to a pointer[.](#5.sentence-1)

A pointer converted to an integer of sufficient size (if
any such exists on the implementation) and back to the same pointer type
will have its original value ([[basic.compound]](basic.compound "6.9.4 Compound types"));mappings between pointers and integers are otherwiseimplementation-defined[.](#5.sentence-2)

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L4939)

A function pointer can be explicitly converted
to a function pointer of a different type[.](#6.sentence-1)

[*Note [4](#note-4)*:

The effect of calling a function through a pointer to a function
type ([[dcl.fct]](dcl.fct "9.3.4.6 Functions")) that is not the same as the type used in the
definition of the function is undefined ([[expr.call]](expr.call "7.6.1.3 Function call"))[.](#6.sentence-2)

â *end note*]

Except that converting
a prvalue of type âpointer to T1â to the type âpointer toT2â (where T1 and T2 are function types) and
back to its original type yields the original pointer value, the result
of such a pointer conversion is unspecified[.](#6.sentence-3)

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L4957)

An object pointer
can be explicitly converted to an object pointer of a different type[.](#7.sentence-1)[53](#footnote-53 "The types can have different cv-qualifiers, subject to the overall restriction that a reinterpret_­cast cannot cast away constness.")

When a prvalue v of object pointer type is converted to
the object pointer type âpointer to cv Tâ, the result is static_cast<cv T*>(static_cast<cv void*>(v))[.](#7.sentence-2)

[*Note [5](#note-5)*:

Converting a pointer of type âpointer to T1â
that points to an object of type T1 to the type âpointer to T2â
(where T2 is an object type
and the alignment requirements of T2 are no stricter than those of T1)
and back to its original type yields the original pointer value[.](#7.sentence-3)

â *end note*]

[8](#8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L4978)

Converting a function pointer to an object pointer
type or vice versa is
conditionally-supported[.](#8.sentence-1)

The meaning of such a conversion isimplementation-defined,
except that if an implementation
supports conversions in both directions, converting a prvalue of one type to the other
type and back, possibly with different cv-qualification, shall yield the original
pointer value[.](#8.sentence-2)

[9](#9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L4988)

The null pointer value ([[basic.compound]](basic.compound "6.9.4 Compound types")) is converted to the null pointer value
of the destination type[.](#9.sentence-1)

[*Note [6](#note-6)*:

A null pointer constant of type std​::​nullptr_t cannot be converted to a
pointer type, and a null pointer constant of integral type is not necessarily
converted to a null pointer value[.](#9.sentence-2)

â *end note*]

[10](#10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L4997)

A prvalue of type âpointer to member of X of type T1â
can be explicitly converted to a prvalue of a different type âpointer to member ofY of type T2â if T1 and T2 are both
function types or both object types[.](#10.sentence-1)[54](#footnote-54 "T1 and T2 can have different cv-qualifiers, subject to the overall restriction that a reinterpret_­cast cannot cast away constness.")

The null member pointer value ([[conv.mem]](conv.mem "7.3.13 Pointer-to-member conversions")) is converted to the
null member pointer value of the destination type[.](#10.sentence-2)

The result of this
conversion is unspecified, except in the following cases:

- [(10.1)](#10.1)

  Converting a prvalue of type âpointer to member functionâ to a
different pointer-to-member-function type and back to its original type
yields the original pointer-to-member value[.](#10.1.sentence-1)

- [(10.2)](#10.2)

  Converting a prvalue of type âpointer to data member of X of type T1â to the type âpointer to data member of Y of type T2â (where the alignment requirements of T2 are
no stricter than those of T1) and back to its original type
yields the original pointer-to-member value[.](#10.2.sentence-1)

[11](#11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L5025)

If v is a glvalue of type T1,
designating an object or function *x*,
it can be cast to the type âreference to T2â
if an expression of type âpointer to T1â
can be explicitly converted to the type âpointer to T2â
using a reinterpret_cast[.](#11.sentence-1)

The result is that of *reinterpret_cast<T2 *>(p) where p is a pointer to *x* of type âpointer to T1â[.](#11.sentence-2)

[*Note [7](#note-7)*:

No temporary is materialized ([[conv.rval]](conv.rval "7.3.5 Temporary materialization conversion")) or created,
no copy is made, and
no constructors ([[class.ctor]](class.ctor "11.4.5 Constructors")) or conversion
functions ([[class.conv]](class.conv "11.4.8 Conversions")) are called[.](#11.sentence-3)[55](#footnote-55 "This is sometimes referred to as a type pun when the result refers to the same object as the source glvalue.")

â *end note*]

[53)](#footnote-53)[53)](#footnoteref-53)

The
types can have different cv-qualifiers, subject to
the overall
restriction that a reinterpret_cast cannot cast away constness[.](#footnote-53.sentence-1)

[54)](#footnote-54)[54)](#footnoteref-54)

T1 and T2 can have
different cv-qualifiers, subject to
the overall restriction that a reinterpret_cast cannot cast away
constness[.](#footnote-54.sentence-1)

[55)](#footnote-55)[55)](#footnoteref-55)

This is sometimes referred to as a type pun
when the result refers to the same object as the source glvalue[.](#footnote-55.sentence-1)
