3 ms·
As I understand it UB was not really intended to be for optimisation. It was so that C could compile on wildly different architectures that existed at the time.
by IshKebab 6mo ago
As I understand it UB was not really intended to be for optimisation. It was so that C could compile on wildly different architectures that existed at the time.
Today we don't have nearly the variety of architectures, so they in theory C doesn't need nearly as much UB (like more modern languages).
Although there is one modern case where C's "anything goes" attitude has actually helped: CHERI works pretty well with C/C++ even though pointers are double the size they normally are, because doing so many things with pointers is UB (I assume because of segmented memory). CHERI is a slightly awkward target for Rust because Rust makes more assumptions about pointers - specifically that pointers and addresses are the same size.
- bombcar 6mo agoWhich is a form of optimization- if you don’t require something that may be incredibly difficult on a given CPU it makes portability easier. The reality is these are all edge conditions rarely encountered.
- kobebrookskC3 6mo agois the fact that CHERI works better with C/C++ because of C/C++'s "anything goes" attitude, or simply that any hardware design that didn't support C/C++ well was discarded?