On Sat, Oct 13, 2012 at 6:25 PM, Dumitru Ungureanu <
itmi...@gmail.com> wrote:
> I imagine compiling the source would change a few things, variables names
> being one.
Compiling the source allocates a memory location corresponding to each
variable, and converts all references to the variable to reads/writes
of that memory location. The variable is then "forgotten". Variables
don't really exist at runtime in compiled languages like Go, only
locations in memory storing values of particular types, and memory
locations don't have names.
For example, an int64 variable would have a block of 8 bytes allocated
for it, and then each read and write of the variable would be turned
into an access to the memory address of that 8 bytes.
This is fairly simplified, and there are some more complex aspects.
For example, variables which exist more than once, like local
variables in functions, need to have a separate location each time the
function is called. The compiler can try to keep a variable's value in
registers and never give it a memory location, for improved
performance, if it doesn't alter behaviour of the code. That kind of
thing. The way all this works is implementation details, though, and
doesn't need to be fully understood, so long as you have a grasp of
the basic model.
All this means that variables don't "have" names, as such, at runtime.