Nowadays compilers optimize crazy things. Especially gcc and clang sometime do really crazy transformations.
So, I'm wondering why the following piece of code is not optimized:
#include <stdio.h>
#include <string.h>
int main() {
printf("%d\n", 0);
}
I would expect a heavy-optimizing compiler to generate code equivalent to this:
#include <stdio.h>
#include <string.h>
int main() {
printf("0\n");
}
But gcc and clang don't apply the format at compile-time (see https://godbolt.org/z/Taa44c1n7). Is there a reason why such an optimization is not applied?
I see regularly that some format-arguments are known at compile-time, so I guess it could make sense (especially for floating-point values, because there the formatting is probably relatively expensive).