Same Bits Three Ways

#include <bit>
#include <cstring>

float f = 1.0f;

unsigned a = *reinterpret_cast<unsigned*>(&f);   // (A)

unsigned b;
std::memcpy(&b, &f, sizeof b);                   // (B)

unsigned c = std::bit_cast<unsigned>(f);         // (C)

sizeof(float) == sizeof(unsigned) == 4. Which lines have defined behaviour?

A

(A) and (C); memcpy is a library call and cannot be constant-folded

B

(B) and (C); (A) is undefined behaviour

C

All three; the objects are the same size so the reinterpretation is valid

D

(C) only; memcpy between unrelated types is also undefined