: warning: macro argument "x" would be stringified in
traditional C
19.6 优化
GCC
采用了许多技术使得生成的可执行程序更小、运行更快。这些技术都倾向于降低程
序源代码与机器码之间“一对一”的对应关系,进而导致调试更加困难。因此,通常在
程序已经完成测试与调试之后,才会应用相关的优化技术。
有两类优化选项。可以通过以
-f
(代表
flag
)开头的选项,指示需要采用的优化技
术,例如,
-fmerge-constants
选项会造成编译器将一致的常量放在同一个位置,甚
至适用于在不同源文件之间一致的常量。你也可以采用
-O
选项系列(
-O0
、
-O1
、
-O2
和
-O3
)设
定优化等级,可一次累积采用多种优化技术。
19.6.1 -O等级
每个
-O
选项都代表多个优化技术的集合。
-O
优化等级是递增的:
-O2
不仅包括
-O1
提供的
所有优化,还包括其他优化,
-O3
对于
-O2
也同样如此。
GCC
手册中介绍了不同等级的详
细描述,以及每个等级代表了哪些
-f
选项。下面是每个等级的简单描述:
-O0
关闭所有的优化选项。
-O
、
-O1
让可执行文件更小、执行得更快,但是不会因此增加过多的编译时间。所采用的技
术包括:合并一致的常量、优化基本循环,以及在连续函数调用后对栈操作分组。
如果
-O
的后面没有数字,就等同于
-O1
。
-O2
应用几乎所有支持的优化技术,只要这些优化技术不涉及程序大小与执行速度之 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.
O’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
I wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
I’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
I'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.