-O2 optimizes printf(“%s\n”, str) to puts(str)

前端 未结 3 613
自闭症患者
自闭症患者 2020-12-11 19:54

Toying around with clang, I compiled a C program containing this line:

printf(\"%s\\n\", argv[0]);

When compiling without opti

3条回答
  •  情歌与酒
    2020-12-11 20:33

    puts is a much smaller function than printf, executables are typically half the size. printf is only needed when converting numbers to strings for printing, you can do this using itoa()

提交回复
热议问题