Advertisement
tinyevil

Untitled

Dec 10th, 2017
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. Lets say there is a function
  2.  
  3. bool halts(const char* program, const char* input);
  4.  
  5. which always returns true, if "program" when compiled with gcc, halts given the "input" on stdin.
  6. and always returns false, if "program" when compiled with gcc, runs forever.
  7.  
  8. Let's define:
  9.  
  10. bool invert(bool x){
  11. if ( x ){
  12. for(;;){}
  13. }
  14. return true;
  15. }
  16.  
  17. Now, lets write in a file "test.c" source code for halts, and invert, and this main function:
  18.  
  19. int main(int arg, char* argv[]){
  20. char* s = read_everything_from_stdin();
  21. invert(halts(s, s));
  22. return 0;
  23. }
  24.  
  25. Now lets run "gcc test.c -oa.exe && a.exe <test.c"
  26.  
  27. Now halts(s, s) evaluates if "test.c" with "<test.c" as input exits or runs forever.
  28. If it returns "true", then invert(true) halts, so halt was wrong.
  29. If it returns false, then invert(false) returns, so halt was wrong.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement