I understand I did not make myself clear. My doubt, I think, could be summed up in this:
In an executable file(machine code) how are “variables” represented? Are they static memory addresses? Does the compiler gives each one a specific “name” (or just keeps the one you gave them)?
Expressed in code:
int x=5;
//Bunch of code
cin>>y;
cout<<x+1;
How does the program in each and every machine knows which address is going to hold the value 5, to hold the inputed value, to add 1 to the value it now holds and finally print that same value.
–João
Here is a simple program in C:
If you compile it with
gcc -m32 -S -O0 -o main.s main.cunder Linux, you’ll get something like thisAs you can see, in this case, variables’ addresses are calculated as offsets of a base pointer of a function. If you enable optimisations, variables’ values may be stored in registers.