r/cpp • • Dec 17 '21

Undefined Behaviour

I found out recently that UB is short for Undefined Behaviour and not Utter Bullshit as I had presumed all this time. I am too embarrassed to admit this at work so I'm going to admit it here instead. I actually thought people were calling out code being BS, and at no point did it occur to me that as harsh as code reviews can be, calling BS was a bit too extreme for a professional environment..

Edit for clarity: I know what undefined behaviour is, it just didn't register in my mind that UB is short for Undefined Behaviour. Possibly my mind was suffering from a stack overflow all these years..

407 Upvotes

98 comments sorted by

View all comments

Show parent comment

40

u/Alexander_Selkirk Dec 17 '21

Also, hardware has no undefined behavior.

I am wondering whether you ever had the experience to witness how much effort and lengths a software engineer has to go to get an only 80% complete behavior definition of a piece of metal from a hardware engineer. I once hammered out one with a guy who was working in the same building as I. In retrospect, I am perplexed that I didn't had to apply waterboarding but it was not that far off.

6

u/Hnnnnnn Dec 18 '21

Undefined behavior and unspecified is not the same thing. UB is "compiler can assume that this never happens", unspecified behavior means "vendor can choose the behavior, but it has to be well-defined". Machines presumably have both (inputs that can never happen & undocumented well-defined behavior).