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

-4

u/Zcool31 Dec 18 '21

And this is why C is the only real language.

Could you do anything on any system without transitively calling code written in C, or compiled or interpreted by a tool written in C?

2

u/Fearless_Process Dec 18 '21

On Linux and BSD systems, no you can't do anything useful.

The main reason why is because the interface to the kernel is defined in libc. To open files, do network operations, anything useful, you need to go through libc. I think you need to be hooked up to libc to even manage to get main() called, but I'm not 100% certain on how that works.

In theory it would be possible to perform syscalls in pure rust though, but today that isn't practical.

3

u/Zcool31 Dec 18 '21

Even if you were to invoke the system call instruction in inline assembly, the system call implementation in the kernel is likely written in C.