Yeah I think you’re right with that, did what they wanted either way I guess but it’s definitely UB, it’s similar to having a union and accessing an inactive member
Type punning though a union is not UB in C. It is UB in C++. Quick inverse square root is type punning through a cast, which is UB in both C and C++ since it violates strict aliasing.
To elaborate, C does not guarantee that type punning through a union will work, but it also doesn't affirmatively mark it as UB. It is implementation defined/unspecified with most compilers supporting it on most platforms. The technical term is "IB with possible trap" iirc
View all comments
Show parent comment
2
u/Potterrrrrrrr Feb 12 '26
Yeah I think you’re right with that, did what they wanted either way I guess but it’s definitely UB, it’s similar to having a union and accessing an inactive member