2 ms·
The compiler can assume that argc will not change within the loop so it can optimize it. I just looked up the assembly output from gcc and it pulls the argc>1 o
by pkaye 9y ago
The compiler can assume that argc will not change within the loop so it can optimize it. I just looked up the assembly output from gcc and it pulls the argc>1 outside of the loop and replaced the printf with puts. So something like:
if argc>1
for (;;) puts(argv[1])
else
for (;;) puts("y")
The replacing of printf with puts is based on gcc having specific knowledge about the printf library function.
- ben_bai 9y agoThis is exactly the OpenBSD implementation.