logoalt Hacker News

maple3142yesterday at 8:52 AM2 repliesview on HN

Is this a correct understanding of UB in C? A program P has a set of inputs A that do not trigger UB, and a complementary set of inputs B that do trigger UB. A correct compiler compiles P into an executable P'. For all inputs in A, P' should behave the same as P. However, for any input in B, the is absolutely no requirements on the behavior of P'.


Replies

simonaskyesterday at 8:54 AM

Intuitively yes - the program will be compiled as if B-inputs are never passed to the program, and that can include eliminating code that tries to detect B-inputs.

show 1 reply
1718627440yesterday at 10:15 AM

Yes, that's a good summary.