Does C++ code compile to assembly code? If we have C++ code, will we be able to get assembly code?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
It depends on the compiler. There are no real rules what c++ compiles into, except at some point it should be able run on a computer. Most compilers has a switch to compile to assembly.
With gcc you can add -S to compile into a .asm file.
For visual studio see http://codegem.org/2008/10/generate-assembly-from-c-code-in-visual-studio
Your code has to be understood by the machine, and, as it is not interpreted nor running in a VM, it is first transformed in assembly. You can get this assembly code by using the
-S
flag in your g++ compile options (as long as you are using g++ of course).should do the trick.
The vast majority of C++ compilers will convert the C++ source into object files (machine code with enough control information to be linked into an executable). They may actually generate assembly language as an interim step and even use a separate assembler for processing the assembler source, but you'll generally never see that. For example, you have to actually go out of your way to get
gcc
to generate assembly code (.s file) by using the-S
flag. Normally, you would never see the assembly.But the C++ standard doesn't mandate the final form that's output from the compiler, just that the code has to behave in a certain way when you run it.
In fact, the earliest C++ "compilers" actually generated C source code and then compiled that.
You can have your C++ compiler generate object code, Java byte code, or even GWBASIC, should you be feeling masochistic.