TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

The most useful GCC options and extensions

62 点作者 antoarts将近 14 年前

11 条评论

gaius将近 14 年前
<i>"If Java had true garbage collection, most programs would delete themselves upon execution." — Robert Sewell</i><p>Nice ;-)
评论 #2753235 未加载
tedunangst将近 14 年前
I was definitely not expecting an article about useful GCC options to mention -trigraphs. The -ansi option isn't particularly useful either, imo, since just about every interesting program is going to do something crazy like open a network socket or list the files in a directory.<p>By far the most useful gcc extension wasn't mentioned at all. typeof().
评论 #2751871 未加载
pdovy将近 14 年前
Has anybody used the __builtin_expect feature to good effect? We had been using this extensively in our codebase in places where there is an obvious common "fast path".<p>I tried an experiment where I did a comparison of the __builtin_expect version against a version with our likely/unlikely macros defined to the identity, and I actually saw no difference, which was disappointing. When I did some digging I found this blog post: <a href="http://bitsup.blogspot.com/2008/04/measuring-performance-of-linux-kernel.html" rel="nofollow">http://bitsup.blogspot.com/2008/04/measuring-performance-of-...</a> which suggests the same result for the Linux kernel.<p>FWIW GCC also has a reasonable set of PGO options (not mentioned in this article), and those actually can (anecdotally) make a noticeable difference, although you're subject to the overtraining problem if you're not careful.
ryanpetrich将近 14 年前
Another useful GCC extension is statements within expressions:<p>#define max(a,b) ({ typeof (a) _a = (a); typeof (b) _b = (b); _a &#62; _b ? _a : _b; })
defen将近 14 年前
Computed goto: <a href="http://gcc.gnu.org/onlinedocs/gcc-3.4.1/gcc/Labels-as-Values.html" rel="nofollow">http://gcc.gnu.org/onlinedocs/gcc-3.4.1/gcc/Labels-as-Values...</a>
matthavener将近 14 年前
A few others I use are -Wsign-compare and -Wformat-nonliteral. Sign compare warns on possible bugs/vulnerabilities due to comparing signed and unsigned values. Using nonliteral formats can lead to vulnerabilities (such as the famous attacks on FTP servers <a href="http://seclists.org/bugtraq/1999/Sep/328" rel="nofollow">http://seclists.org/bugtraq/1999/Sep/328</a>)
评论 #2752902 未加载
afhof将近 14 年前
Sometimes when compiling and trying to use system calls gcc will complain about the functions not existing. This is usually because of some preprocessor guard not being defined. An easy way to see what macros have been defined is to run gcc with the "-E -dM" flags.
freedrull将近 14 年前
-fmudflap always interested me, but I never seem to remember it when I'm actually confronting a hard to debug pointer issue.
pwpwp将近 14 年前
My favorite is the "weak" attribute. <a href="http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html" rel="nofollow">http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html</a><p>Makes separate compilation for languages that compile to C <i>much</i> easier.
评论 #2752973 未加载
16s将近 14 年前
Is it me, or is this statement from the article wrong:<p><i>"All warnings can be enabled with -w."</i><p>man g++ says:<p><i>"-w Inhibit all warning messages."</i><p>Inhibit means to prevent (not to enable).
评论 #2753335 未加载
评论 #2754223 未加载
rnicholson将近 14 年前
No love for --coverage?
评论 #2753061 未加载