摘要: 为什么在内核中碰到很多 #defines ... do{ ... } while(0)?有以下几点原因:1.当宏里面有if时,可以起到封闭代码作用,防止与外面的 if 混淆 比如定义宏,#define FREE1(p) if (p) free (p) 而在代码部分这样调用宏: if (expression) FREE1(p) else printf(“expression was false.\n”) ; 展开后,else会和宏中的if配对了,这就错了。但是宏写成如下的形式就永远不会错了 #define FREE4(P) do {if(p) free(p)}; while(0)... 阅读全文
posted @ 2012-02-06 14:55 only_eVonne 阅读(438) 评论(0) 推荐(0) 编辑
摘要: 在GCC手册中对__builtin_expect()的描述是这样的:long __builtin_expect (long exp, long c) You may use __builtin_expect to provide the compiler with branch predictioninformation. In general, you should prefer to use actual profile feedback for this(‘-fprofile-arcs’), as programmers are notoriously bad at predicting 阅读全文
posted @ 2012-02-06 14:28 only_eVonne 阅读(2954) 评论(0) 推荐(1) 编辑