Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find how C++ compiler implements something except inspecting emitted machine code?

Suppose I crafted a set of classes to abstract something and now I worry whether my C++ compiler will be able to peel off those wrappings and emit really clean, concise and fast code. How do I find out what the compiler decided to do?

The only way I know is to inspect the disassembly. This works well for simple code, but there're two drawbacks - the compiler might do it different when it compiles the same code again and also machine code analysis is not trivial, so it takes effort.

How else can I find how the compiler decided to implement what I coded in C++?

like image 250
sharptooth Avatar asked Dec 02 '10 06:12

sharptooth


People also ask

How is C compiled to machine code?

The C programming language is what is referred to as a compiled language. In other words, C programs are implemented by compilers, which translate source code into machine-readable code (more on that later). The GNU Compiler Collection (GCC) is one such compiler for the C language.

How is C compiler compiled?

It is done with the help of the compiler. The compiler checks the source code for the syntactical or structural errors, and if the source code is error-free, then it generates the object code. The c compilation process converts the source code taken as input into the object code or machine code.

How does compiler check code?

The compiler verifies that the code's syntax is correct, based on the rules for the source language. This process is also referred to as parsing. During this step, the compiler typically creates abstract syntax trees that represent the logical structures of specific code elements. Semantic analysis.

Does C compile to machine code or assembly?

C is a ahigh-level language which is compiled rather than assembled. Although compilation is very complex, the basic operation resembles that of assembly: Most programs are written in a "high level language" such as C, rather than assembler.


1 Answers

I'm afraid you're out of luck on this one. You're trying to find out "what the compiler did". What the compiler did is to produce machine code. The disassembly is simply a more readable form of the machine code, but it can't add information that isn't there. You can't figure out how a meat grinder works by looking at a hamburger.

like image 185
Karl Knechtel Avatar answered Oct 14 '22 14:10

Karl Knechtel