4 ms·
I think many people overlook that "undefined behavior" mainly limits portability. Invoking undefined behavior won't cause your program to do random things, it j
by blackguardx 9y ago
I think many people overlook that "undefined behavior" mainly limits portability. Invoking undefined behavior won't cause your program to do random things, it just might not do the same thing when you switch to a different compiler. This is still a big problem, but not as big as people make it out to be, in my opinion. I think undefined behavior problems in the standard could be fixed, but compilers would need special flags for backwards compatibility with programs that rely on it.
- aw1621107 9y ago> "undefined behavior" mainly limits portability I had the impression that some things are UB because they can't specify a single behavior that would be efficient across all platforms C targets.
- fjsolwmv 9y agoNo that's implementation-defined. Undefined means code that is logically incorrect, but too expensive for the compiler/runtime to check and handle (reject) it. A simple example is array out of bounds access. It's too expensive to demand the compiler prevent it or guarantee to trigger some kind of signal at runtime. But if you are willing to pay the cost , you can use a language or compiler that is safer and promises to throw an exception or provides safe statically sizd arrays
- UncleMeat 9y ago> Invoking undefined behavior won't cause your program to do random things According to the spec, it literally can. The compiler is free to replace your entire program with unrelated functionality. It can ever do a different thing each time it compiles the program. There are implementation specific behaviors (# of bits in a char), which are different.
- deleted 9y ago[deleted]
- khedoros1 9y agoUndefined behavior is undefined even using the same version of the same compiler. If it does produce the same repeatable behavior, consider it luck. Implementation-defined behavior limits portability in the way you describe, but UB's not the same thing. IB should behave the same way in the same implementation. UB doesn't have to.