Guess the language by the error
Aug. 6th, 2020 04:54 pmchar isEven(unsigned int n);
char isOdd(unsigned int n) {
return n && isEven(n+1);
}
char isEven(unsigned int n) {
return isOdd(n+1);
}
int main(int argc, char** argv) {
printf("%d %d\n", argc, isEven(argc));
return 0;
}This program decides all integers are not even, if compiled with gcc -O2.
The cause of this is that both isOdd and isEven were replaced by a constant 0. Apparently, because http://eel.is/c++draft/intro.progress allows the compiler to assume that isOdd can only return 0, without proving that it terminates.
Basically, if it terminates, then it can only return through "n && ..." evaluating to 0. But now it is ok to assume it always returns 0 - because that's the only way it could have terminated.
All it took to solve Entscheidungsproblem, was a committee of clever engineers: all C programs terminate. Give Gödel some slack! He couldn't have known that, could he?