Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
126 views
in Technique[技术] by (71.8m points)

c++ - Why are interpretations of a binary file so scrambled?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Source code describes the behaviour of a program, not a sequence of instructions to perform a task. The compiler takes the description of behaviour and, assuming optimizations are turned on, produces the best list of instructions to perform the task that it can make. The higher the optimization level requested of the compiler, the more effort the compiler puts into finding a more efficient solution.

Thanks to the As-If Rule, the compiler is allowed to so anything it wants to the code to produce the most efficient program it possibly can so long as none of the observable behaviours described by the source code are changed1. You may find whole swathes of code are gone because they had no observable result or that observable result resolved to a constant the compiler could pre-compute and store.

When the compiler's done the output should look like the input went through a blender.

As for why the binary output is a jumbled mess, that's binary, baby. It's not meant to be human readable. Computers, on the other hand, love the stuff.

1 Mind you, there are a few exceptions, like copy elision, to the no behaviour changes rule.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...