3 ms·
> What has stopped people from creating a standard with no undefined behavior? Because making C safer would introduce a lot more complexity in the runtime envi
by bluetomcat 8y ago
> What has stopped people from creating a standard with no undefined behavior?
Because making C safer would introduce a lot more complexity in the runtime environment and instrumentation, and that is even hard to achieve correctly or has varying performance implications across all ISAs that C compilers are currently targeting.
Consider out of bounds indexing. To determine that an instruction is touching a memory region that is not, in abstract terms, a C array or a memory allocation by malloc and friends, now you need to insert long traps in memory, and even then, there is nothing stopping you from accessing array `b` through, for example, `a + 42`.
- archgoon 8y agoRemoving undefined behavior is not actually the same as making C safer. In fact, in a sense, well defined C exists (many versions in fact), it's whatever your C compiler spits out with whatever combination of flags have been passed in.