~/talk

Type punning in modern C++

Talkat CppCon 2019 · 2019-09-15..09-20· [compilers-and-language-design]
links:none on file
slides:none on file

Compares concrete techniques — reinterpret_cast and unions cause undefined behaviour; memcpy is the portable fix — using the Quake fast inverse‑sqrt as a concrete example; shows clang, GCC and MSVC all generate identical optimized code when memcpy replaces UB casts. Explains why: strict‑aliasing, alignment and object‑lifetime rules; highlights C++20’s bit_cast (constexpr) and the proposed start_lifetime_as wording plus a future layout‑as attribute to make several remaining patterns safe.

AI-written summary · about

  1. 0:00Start
  2. 1:52Type Padding
  3. 2:36Code Example
  4. 5:21Type Planning
  5. 8:04Reinterpret Casts
  6. 8:22Undefined Behavior
  7. 16:37Compile Explorer
  8. 20:23Strict Agassiz
  9. 20:48Object Lifetime Rules
  10. 24:59Create an Object
  11. 27:17Object Types Have Alignment Requirements
  12. 29:21Line Storage
  13. 58:24When You'Re Tight Punting between a Tau or between a Kerr Buffer and a Widget Is It Defined Behavior To Put both into a Union and Mem Copy from What Union Member to the Other Sorry To Put What into a Union and Put both the T and the You into the Union and Use the Mem Copy Technique To Copy from One Union Member to the Other All Right So if You Have these Kind of Unions and We Have this Other Rule That I Didn't Talk about Which Is the Common Initial Sequence Rule Depending on What You'Re Doing You Might Be Able To Get this to Work Let's Look at some Codes
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.