+ 1
Just asking whether C++ compilers execute the codes simultaneously or orderly
it's better if you can visualize your point by writing a code. Thanks :)
3 Answers
+ 1
Compilers do not execute code, they translate it. If you make a .exe file with your compiler, the c++ code translates to machine language.
Machine language doesn't really know about classes or functions so calling the output of a compiler "orderly" is maybe not right.
Compilers do optimizations on your code to make it faster, and that sometimes also means switching lines of code around if it can. Some compilers will also try to make multiple things run at once if possible. An example of this would be making use of SSE extensions:
Say you add two arrays, like result[i] = a[i] + b[i], in a loop, and your arrays are all 32-bit integers. Now on your CPU there are some registers that are 128 bit wide and if you use them, 96 bit will be unused each addition. SSE can now put 4 32-bit integers into one 128-bit register and so you can add 4 numbers with one instruction, for a ~400% performance increase. That's called "instruction-level parallelism". Using SSE in C++ directly is pretty messy, you can google it.
+ 2
Há»ng VÄ©
I believe that is a question for a developer.
One involved with the compiler you are refering to.
0
But keep in mind that you are writing the code and telling the computer what to do. If you write your code in a way that doesn't use many threads ("makes code run simultaneously"), the compiler will not magically make it so. Every now and again it will use small tricks, but only if doing the trick and not doing the trick has the same result, if that makes any sense. That's in C++ anyway.