Consts really don't have an address, they may not even be stored anywhere at all. Let's look at this small program and see what happens in its intermediate C source code:
const x = 10
echo x
echo x + 1
The relevant C code looks like this:
STRING_LITERAL(TMP5, "10", 2);
STRING_LITERAL(TMP6, "11", 2);
NIM_EXTERNC N_NOINLINE(void, xInit)(void) {
printf("%s\012", ((NimStringDesc*) &TMP5)? (((NimStringDesc*) &TMP5))->data:"nil");
printf("%s\012", ((NimStringDesc*) &TMP6)? (((NimStringDesc*) &TMP6))->data:"nil");
}
So the calculation is actually done at compile time and the final strings for echo
are stored in the program instead of the int x
.