3 ms·
> While there is an abstract machine of sorts defined in the standard, a lot is left out of the standard in UB... This is exactly why, on modern C compilers,
by gwd 7y ago
> While there is an abstract machine of sorts defined in the standard, a lot is left out of the standard in UB...
This is exactly why, on modern C compilers, you have to start thinking of C as an abstract machine -- because that's what the compiler writers think they're doing.
But unlike abstract machines for older languages designed to be mathematically pure, or new abstract machines for newer languages designed to keep you from making stupid mistakes, the C abstract machine is full of bear-traps, such that if you ignore the "C is an abstract machine" warning, nearly any simple-but-obvious program is probably vulnerable to a dozen UB vulnerabilities.
- mpweiher 7y ago> because that's what the compiler writers think they're doing. Yep. And that's why modern compilers are such a shit show. > any simple-but-obvious program is probably vulnerable to a dozen UB vulnerabilities. I was shocked (well not really, but it is shocking) when a Googler and member of the C++ standards committee said in a talk (probably some C++ conf) that he works with the best C++ engineers in the world and none of them can write even small amounts of correct code according to the standard. Head explodes. Maybe, just maybe, there's something wrong with the standard and how it is interpreted? But apparently the thought never entered his mind.
- throwaway17_17 7y agoHard agree on ‘that’s what compiler writers think they’re doing.’ I don’t even think the concept of C being the ISA for some abstract machine is a bad concept. However, and I think it gets to the heart of your point, the compiler writers only do this or adopt this attitude when it allows them to hand wave. There isn’t the consistency that should be present in an abstract machine implementation. Now that I’ve rambled, I may make the most of this Stay-at-Home situation and write something up using the C as abstract machine concept.