Consts really have no address; they cannot be saved at all. Take a look at this little program and see what happens in its intermediate C source code:
const x = 10
echo x
echo x + 1
The corresponding C code is as follows:
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 performed at compile time, and the final lines for echoare stored in the program instead of int x.
source
share