How can C / C ++ compile for the correct architecture?

Well, I start with computer programming like C ++ and c. I have a strong question about processors that will give me a better understanding of where my code will run.

So, let's say I compile a C ++ program. It is currently compiled for low-level assembly code. This code has processor instructions for my code. Since each processor has a different set of instructions, I wanted to know where my code would run. For example, I compile my programs in blocks of code. How do I know if I'm compiling it for a 32-bit or 64-bit computer? Can I change it? What is the difference between two 32-bit processors, one is an i5 and the other is a pentium 4? (will my code work on dual processors?)

thank:)

+3


source to share


1 answer


How do I know if I'm compiling it for a 32-bit or 64-bit computer?

You must tell the compiler when you are building your program. It probably has some defaults - check its documentation.

Can I change it?

Perhaps it depends on your compiler. If it has the required parameters, then yes. clang

for example has a flag -arch

.



What is the difference between two 32-bit processors, one is an i5 and the other is a pentium 4?

If both implement the same instruction set, then they are nearly equivalent for compiling your software. It is possible that optimization for a particular machine might work better on one or the other.

will my code run on two processors?

In the case of the example you gave, perhaps yes.

+5


source







All Articles