ANSWERS: 1
  • Well, I don't think const is going to make it bigger...only smaller, or the same. The const will absolutely be replaced with its value in your code. const int x = 3; int main() { return x + 4; /* on x86 generates mov eax,7 and x is not referenced from memory*/ } Whether or not the const occupies space in your data section may be dependent on the compiler and optimization settings. When in doubt, generate a map file by adjusting your linker settings. The map file will tell you what data has been assigned to your data section. You may also be able to tell if the data is actually appearing in your binary, or if it is simply that address space has been reserved for it. Something like a const int may not need to appear in your data section at all, unless you use a pointer to it. EXAMPLE - can be optimized away. const int x = 5; int main() { return x; } EXAMPLE - probably need the actual memory because it is referenced by address const int x = 5; int main() { return (int) &x; /* return pointer as int */ }

Copyright 2023, Wired Ivy, LLC

Answerbag | Terms of Service | Privacy Policy