Hacker News new | ask | show | jobs
by abbeyj 192 days ago
> We all know that strlen will return 5, but some compilers don't: https://godbolt.org/z/M7x5qraE6

I feel like it is unfair to blame the compiler when you've explicitly asked for `/O1`. If you change this to `/O2` or `/Ox` then MSVC will optimize this into a constant 5, proving that it does "know" that strlen will return 5 in this case.

1 comments

Fair point. It doesn't do the optimization if you ask to optimize for size '/Os' either.