3 ms·
> Undefined behavior: Anything is allowed to happen, and you might no longer have a computer left after it all happens. and > The moment your program contains
by moring 4y ago
> Undefined behavior: Anything is allowed to happen, and you might no longer have a computer left after it all happens.
and
> The moment your program contains UB, all bets are off.
Does this include that a compiler, when it can prove that a program it compiles contains UB, erase your disk as part of the compilation process? i.e. without you ever running the compiled program.
- matkoniecz 4y ago> Does this include that a compiler, when it can prove that a program it compiles contains UB, erase your disk as part of the compilation process? i.e. without you ever running the compiled program. No, but technically compiler would not violate specification by compiling program that on running will scan your disk for secret data, publish it online, apply ransomware to your disk and deliberately destroy your SSD.
- dottedmag 4y agoAlso known as "nasal demons"
- bmacho 4y agoWhat about the C programs? I guess the program void main(){}; is allowed to row hammer your RAM and inspect and modify the states of other programs, but is it allowed e.g. to delete your file system through a system call?
- matkoniecz 4y agoIs it program with UB? If yes, then compiler can compile program doing literally anything* and be in compliance with standards as defined. *including hacking Pentagon to order drone strike on location where it was compiled. Or summoning demons. Or deleting your file system through a system call.
- deleted 4y ago[deleted]
- Denvercoder9 4y agoThe C specification doesn't say anything about what a compiler may or may not do during compilation. It only specifies how the compiled program should behave. So, yes, the C specification allows a standard-conforming compiler to erase your disk during compilation. It even allows it to do that if your code doesn't contain UB.
- marcosdumay 4y agoThe Haskell people would say that the compiler may decide to launch the missiles. In practice, it means all bets are off, and yes, depending on your code, you may lose some data.