I always wonder why compilers can\'t figure out simple things that are obvious to the human eye. They do lots of simple optimizations, but never something even a little bit
Did you compile to release code? I think a good compiler detects in your second example that the string is never used an removes the entire loop.