在看代码的时候,偶然看见有的函数这样申明:
void function __P((int));
调用的时候直接使用function()就行了,感觉好奇怪;搜索了一下,在netbsd的maillist有大侠做了解释:
Use the __P macro from the include file for prototypes in header files, for compatibility with non-ANSI compilers. I.e,
void function __P((int));
还有类似用do{ }while(0);来代替某些宏的申明问题:
/*
* Macros are capitalized, parenthesized, and should avoid side-effects.
* If they are an inline expansion of a function, the function is defined
* all in lowercase, the macro has the same name all in uppercase. If the
* macro needs more than a single statement, use do { ... } while (0), so
* that * a trailing semicolon works. Right-justify the backslashes; it
* makes it easier to read.
*/
#define MACRO(x, y) do { \
variable = (x) + (y); \
(y) += 2; \
} while (0)
阅读(1417) | 评论(0) | 转发(0) |