On 2/23/2013 2:49 PM, David-C-CPP wrote:
Can sb explain me how the namespaces, symbols etc. work in low level detail? I read on many places that namespaces guarantee your functions variable to be unique, but what does this mean for the resulting machine code?
Nothing. Symbols and names only have meaning at compile-time. None of them are present in the machine code.
What is meant by symbols, e.g. symbols after compiling example.c or so.
"Symbol" in this context is essentially the same as "name".
Are these symbols variables, or functions?
Both functions and variables have names.
What do symbols do?
Allow parts of the program to refer to entities defined in other parts of the program. For example, you may define a function in one source file, and call it in others. The fact that you are using the same name, or symbol, is what makes the compiler and linker know that you actually mean to refer to the same function in all those places.
I do understand the linker part, that it links symbols of different machine code together, right?
I don't understand what you mean by "symbols of different machine code".
How do functions work in low level? When I e.g. call CPPIsAwesome() (leaving out the parameters etc. I do get the stack part), it is a subroutine. How is a subroutine executed?
The compiler generates a CALL machine instruction. CALL instructs the CPU to push the current value of instruction pointer (IP) onto the stack, then set IP to the address mentioned in the CALL instruction. The next statement executed would be the one at that address - presumably, the first instruction in the body of the function. Eventually, a RET instruction would be encountered, which tells the CPU to pop the previously saved IP vale off the stack, and resume execution from the instruction following the CALL that pushed it there.
Is is just part of the global code?
I'm not familiar with the term "global code". Is there "local code"? In C++, all executable statements are part of some function - there is no code outside of functions.
Or is it simply code with a demand of usage of the stack?
On x86 architecture, with its dearth of CPU registers, pretty much all code demands some usage of the stack.
And last, what is a varialbe?
A named memory location.
maybe a stupid question, but in low level, how does a varialbe look like?
A few consecutive bytes of memory.
Is it the memory address, or the value?
Both. The variable designates a memory address. There's always some value stored in memory at that address.
If I call a variable
You can't call a variable. You can read its value, you can assign a new value to it, or you can take its address.
Igor Tandetnik