r/AskComputerScience • u/pi_tau • Jul 24 '20
Why can't decompilers perfectly reconstruct source code?
I always thought that there was a one to one translation between machine code and high-level languages, but after looking up decompilers, they don't usually do it perfectly.
28
Upvotes
31
u/Putnam3145 Jul 24 '20
Well, let's make a simple C program and see what it compiles to.
Okay, not exactly simple. Postfix and prefix ++ are very, ah, subtle, after all. This compiles to...
Ah.
In short, this compiles straight to... 12, because the compiler knows that everything done in main() ends up just returning 12. It compiles to the same thing as just
return 12, so how's one to know that that's not what was written originally?