3 ms·
Local constant stack values surely can be completely deterministically verified as such by the optimiser even without the `const` modifier. Only if their addre
by caf 7y ago
Local constant stack values surely can be completely deterministically verified as such by the optimiser even without the `const` modifier.
Only if their address doesn't escape.
- AstralStorm 7y agoThe compiler will detect any attempt at taking the address of the variable (including fancy things like most inline assembly) and skip the optimization, marking it as requiring a memory location. However, it can still cheat by rearranging the memory write or even letting linker initialize the address.
- caf 7y agoWe are in violent agreement. An explicitly const-qualified object instead can be replaced with its value even if its address has escaped.
- ljackman 7y agoBy ‘constant stack value’, I was referring to ‘effectively constant’ stack values, i.e. ones who aren’t reassigned in the scope or passed by mutable reference (or indeed are but aren’t actually modified by those functions anyway if the compiler can prove it). My phrasing was probably a bit ambiguous there.