是的,您通常可以预期默认标志会完全不同。幸运的是,您不需要知道标志是什么,也不需要设置它们。
Ubuntu 和 Debian 非常相似,因为 Ubuntu 非常接近 Debian。但是您会看到各种不同的选项,因为 GCC 使用的实际选项是相当技术性的。您可以通过运行以下命令来查看它们:
gcc -Q -v -x c -c /dev/null
这要求 GCC 将 /dev/null 编译为 C 程序 (-x c -c /dev/null) 并打印出一堆开发人员信息 (-Q -v)。我用 GCC 4.4、4.6 和 4.8 运行它,得到了不同的结果。以下是我机器上 4.4 和 4.6 选项的区别:
< -falign-loops
< -fargument-alias
> -fdelete-null-pointer-checks
> -fprefetch-loop-arrays
> -fsched-critical-path-heuristic
> -fsched-dep-count-heuristic
> -fsched-group-heuristic
> -fsched-last-insn-heuristic
> -fsched-rank-heuristic
> -fsched-spec-insn-heuristic
> -fshow-column
> -fstrict-volatile-bitfields
> -ftree-forwprop
> -ftree-loop-if-convert
> -ftree-phiprop
> -ftree-pta
> -ftree-slp-vectorize
> -fvar-tracking-assignments
< -mfused-madd
以下是我机器上从 4.6 版到 4.8 版的差异:
> -faggressive-loop-optimizations
> -fgnu-runtime
> -fgnu-unique
< -finline-functions-called-once
> -finline-atomics
> -fira-hoist-pressure
> -fsync-libcalls
> -ftree-coalesce-vars
< -fvect-cost-model
> -mfxsr
> -mlong-double-80
在我的机器上,GCC 在编译 C 时默认使用 80 个不同的选项!当您编译 C++ 或在不同平台上编译时,这些选项也会发生变化。
不过没关系。您基本上可以忽略所有这些选项,只关注最重要的选项,即各种 -W 警告标志、-O 优化标志(实际上只是大量预选 -f 标志和一些-m——在我的电脑上,-O2 启用了 63 个额外的标志!)和-g 调试数据标志。
当然还有基本标志,例如-std=、-c、-o、-l、-I 等。
我的意思是,你真的需要知道-fbranch-count-reg 做了什么吗?不是真的。