函数的原型在一个 PARAMS 宏中声明,这样 K&R 编译器就仍然能够编译源代码。对于 K&R 编译,PARAMS 从函数的原型中移除 ANSI 参数列表。有些开发人员仍然使用 __P 来处理这个问题,但严格地将,以 `_'(特别是 `__')开始的宏都是留给编译器和系统头文件的,因此使用 `PARAMS' 会比较安全,例如: #if __STDC__
# ifndef NOPROTOS
# define PARAMS(args) args
# endif
#endif
#ifndef PARAMS
# define PARAMS(args) ()
#endif
This macro is then used for all function declarations like this: 接下来,在函数声明中可以这样使用它:
extern int functionname PARAMS((const char *parameter));
欢迎光临 Chinaunix (http://bbs.chinaunix.net/) | Powered by Discuz! X3.2 |