logoalt Hacker News

IshKebabyesterday at 8:49 PM2 repliesview on HN

They don't really. In fact there are many things that are technically UB but are so common that compilers can't really treat them as UB. E.g. type punning via unions.


Replies

el_pollo_diabloyesterday at 9:20 PM

Type punning via unions is not UB in C in general, but it is in C++ IIRC.

I write "in general" because, as with other forms of memory reinterpretation (memcpy or copy through a character type), evaluating a trap representation triggers UB.

show 1 reply
IcyWindowsyesterday at 11:33 PM

Yeah, undefined behavior just means not defined in the specification.

I would argue that most languages only have one compiler so it doesn't matter what is in the specification.