2 ms·
> Fucking compilers, man. They're just acting as agents that derive the logical consequences of the code. The fact that the given example code is "surprising"
by nayuki 2y ago
> Fucking compilers, man.
They're just acting as agents that derive the logical consequences of the code.
The fact that the given example code is "surprising" is analogous to this mathematical derivation:
a = b
a*a = b*a
a*a - b*b = b*a - b*b
(a - b)(a + b) = b(a - b)
(a - b)(a + b)/(a - b) = b(a - b)/(a - b)
^ Divide by 0, undefined behavior!
Everything below is not necessarily true.
a + b = b
b + b = b
2b = b
2 = 1
2 - 1 = 1 - 1
1 = 0
The source of truth about what is/isn't allowed is the C standard, not your personal simplified model of it that may contain dangerous misconceptions. The fact that your mental model doesn't match the document is an education problem, not a problem with the compiler.
- marssaxman 2y ago> They're just acting as agents that derive the logical consequences of the code. In a particularly pedantic, uptight, and sometimes un-helpful way, yes. Compilers don't have to be designed this way; in fact it is a relatively recent development in the history of such tools.
- saurik 2y ago> The fact that your mental model doesn't match the document is an education problem, not a problem with the compiler. Or it is a problem with the document, which is the entire reason we are having this discussion: N3322 argued the document should be fixed, and now it will be for C2y.