Timur Doumler — Type punning in modern C++

preview_player
Показать описание
— —
. . . Type punning is often used in C++ for fast floating-point math, deserialising C++ objects from a sequence of bytes, and other purposes. Popular techniques involve unions, reinterpret_cast, and memcpy. C++20 provides new useful tools, such as bit_cast. And there are proposals to provide even better control over C++ object creation in the future.

This talk is a comprehensive overview of all of these techniques. We will discuss when and how they can be used safely without causing undefined behaviour, what C++ does and does not allow you to do (and why), existing holes in the C++ language, and how to fix them. In the process, we will cover important C++ concepts such as object lifetime, value representations, and aliasing rules.
Рекомендации по теме
Комментарии
Автор

Pretty amazing that C++ has existed as a "low-level language" for so many decades without these tools. It's almost like UB is a feature not a bug.

acf
Автор

This sounds like fucking garbage.
1. If reinterpret cast is useless UB it should not exist.
2. Other books and code recommend reinterpret cast. Such as socket programming.

A compiler that compiles away reinterpret cast is shit and I will never use it.

Furthermore Minggw is based on GCC and I never have this problem with minggw.

dmasterify