3 ms·
Is the proposed solution really the best approach? It seems complicated to me and relies on obscure parts of the language. Maybe the problem (compiler optimizes
by annnnd 12y ago
Is the proposed solution really the best approach? It seems complicated to me and relies on obscure parts of the language. Maybe the problem (compiler optimizes away function call because the result is no longer needed) could be solved like this:
memset(key, 0, sizeof(key));
if (key[0]) // we are using key, so you can't skip memset()
dropDead();
Unless the compilers "understand" memset and still optimize away the last two lines? I would hope not... Does anyone know how aggressive the C optimizers are these days?
- Genmutant 12y agoThe compiler understands memset, so that would probably not work.
- anon4 12y ago> Unless the compilers "understand" memset and still optimize away the last two lines They do. That's the whole "problem" - the compiler knows what memset is and what it does, since it's specified in the standard.
- DSMan195276 12y agoIt's not even that it 'understands' memset, more likely that the memset call is almost immediately inlined into your code making it obvious what's going on.