Hacker News new | ask | show | jobs
by lazyjones 4305 days ago
> In the snippet below, the compiler is allowed to eliminate all code after “leave secrets in array c”

gcc 4.4.5 doesn't though (-O3), it still clears the stack once and performs the comparison.

I believe these optimizations can be defeated by declaring a global

  volatile char fill = 0;
and using that instead of 0 in memset().
1 comments

It's not guaranteed to defeat the optimization. For instance, it could just read fill into two registers and do the comparison there.