【发布时间】:2010-06-23 20:07:06
【问题描述】:
我想编写一个类似 printf 的例程,但不是在功能上,而是我希望该例程与 printf 具有相同的编译检查特性。
例如,如果我有:
{
int i;
std::string s;
printf("%d %d",i);
printf("%d",s.c_str());
}
编译器这样抱怨:
1 cc1plus: warnings being treated as errors
2 In function 'int main()':
3 Line 8: warning: too few arguments for format
4 Line 9: warning: format '%d' expects type 'int', but argument 2 has type 'const char*'
printf 和 co 是编译器区别对待的特殊函数,还是有一些技巧可以让它在任何用户定义的函数上工作?我感兴趣的具体编译器是 gcc 和 msvc
【问题讨论】:
标签: c++ compiler-construction printf typechecking