Driving Compilers (2023)

21 misonic 3 5/5/2025, 2:17:12 AM fabiensanglard.net ↗

Comments (3)

lynx97 · 38m ago
Nitpick: Almost all Hello World C examples are wrong. printf is for when you need to use a format string. Hello World doesn't. Besides:

> puts() writes the string s and a trailing newline to stdout.

int main() { puts("Hello World!"); }

PhilipRoman · 25m ago
Eh, it compiles down to the same thing with optimizations enabled:

https://godbolt.org/z/zcqa4Txen

But I agree, using printf for constant strings is one step away from doing printf(x) which is a big no-no.

Joker_vD · 18m ago
Useless bit of compiler optimizations trivia: the "this printf() is equivalent to puts()" optimization seems to work by looking for the '%' in the format string, not by counting whether there is only one argument to printf(), e.g. if you add 42 as a second argument to the printf() — which is absolutely legal and required by the standard to Work as Intended™ — the resulting binary still uses puts().