Hacker News new | ask | show | jobs
by vardump 1463 days ago
It's a static initialization time FizzBuzz. In this case, I think it's executed before main() is called, and not at compile time.

Unless, of course, you have a very clever compiler that determines memory allocation is not actually allocating anything and that the output is a static string, and there are no side effects. Such a clever compiler could optimize it all into just one "puts" call.

1 comments

Neither GCC nor Clang bake the final string into the data segment. If I had to guess, printf is the one preventing the more fancy optimizations to take place.
I think so too. Also, depending on stdlib output buffering, the external I/O behavior of 100 puts calls is potentially different from just one call.

In other words, there might be a different number of stdout write-calls.