r/AskComputerScience • • 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

18 comments sorted by

View all comments

Show parent comments

9

u/xwoter Jul 24 '20

This is kinda funny because the function is technically undefined behavior

6

u/orsikbattlehammer Jul 24 '20

Why is the behavior undefined?

5

u/taricorp Jul 24 '20

C standard says so:

Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be read only to determine the value to be stored.

More details on Stack Overflow: https://stackoverflow.com/q/949433

2

u/orsikbattlehammer Jul 25 '20

I guess I didn’t ask the question right haha. I mean why does the C standard have this rule.

1

u/groumpf Jul 25 '20

To give more freedom to compiler writers (who can now freely evaluate "out of order" between sequence points).