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 comments

11

u/ArchivistAtNekoIT Dec 17 '21

While that is possible on paper, in practice that probably mean "faster on a platform and slower on others". Platforms have their specificities and idiosyncrasies and those are generally the reason for undefined behaviors

-6

u/Alexander_Selkirk Dec 17 '21

Rust is in some cases faster than C++ in the same (x86_64) hardware, and has virtually no undefined behavior in normal code (code not declared "unsafe"):

https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/rust-gpp.html

And for performance, I think x86_64 is the most relevant platform.

6

u/ArchivistAtNekoIT Dec 17 '21

x86_64 is instantly less relevant on mobile phones (most used devices) and in big tech where ARM is king.

Also, find any rust software that has 0 reliance on unsafe code

-5

u/Alexander_Selkirk Dec 17 '21

x86_64 is instantly less relevant on mobile phones

But so is C++.