5 ms·
Easy talking, name one?
by tinco 13y ago
Easy talking, name one?
- mikeash 13y agoIs it hard? I thought that most languages had fully defined behavior, and that C was an exception to this. In case you want specific examples to poke holes in, let's say Java, C#, and Ada.
- ynik 13y agoOnce you add multithreading into the mix, there's plenty of undefined behavior in almost any language. In particular, compiler optimizations can cause surprising effects in programs without sufficient synchronization. In the Java memory model you still get memory-safety in the presence of race conditions, but other than that the program behavior is pretty much undefined. It's better than undefined behavior in C, but not by much.
- mikeash 13y agoThat's an interesting point, I hadn't thought about multithreading. Is it truly undefined in the nasal demons sense, or is it just that the behavior is hard to predict in advance? I assume everyone reading a discussion about undefined behavior knows what nasal demons are, but just in case someone doesn't: in illustrating just what "undefined behavior" means in C, it has been suggested that it would be perfectly legal for a compiler, upon encountering such, to cause demons to fly out of the programmer's nose. The point being that it's not just a matter of producing an unexpected value or something of that nature, but a completely unexpected behavior. As a real-world example, early versions of gcc would, upon encountering a #pragma (whose behavior is undefined) would start a game of nethack.
- tinco 13y agoIt's hard because yes it's true that Java and C# have fully defined behaviour (at least to my knowledge, and when you assume that the garbage collection is optimal) the operations of the VM's themselves are written in C. So you are still dependant on that the programmers of your VM are in control of the undefined behaviour of C. I know that sounds a bit like a cop out, but it lays the finger on the pain point of modern computing, that whatever we do, we are still so heavily reliant on C for everything low level. How would we come close? I'd say name a language whose JIT directly outputs (x86) assembly, and whose runtime is written in a runtime free version that is output by that same JIT. The only language I know of that can do that atm is Rust.
- moomin 13y agoRust, of course, uses LLVM, which is written in C++.
- Dylan16807 13y agoYou can use defensive C that checks for undefined behavior whenever it could possibly occur to implement the runtime of an undefined-free language. And with intelligent coding you could probably get those checks to be very minimal.
- Ono-Sendai 13y agoJava
- kabdib 13y ago... and now you have two problems :-)
- tel 13y agoSML is the quintessential example. Haskell is pretty good about it, too.