__attribute __((格式(printf的,1,2)))为MSVC? [英] __attribute__((format(printf, 1, 2))) for MSVC?

查看:470
本文介绍了__attribute __((格式(printf的,1,2)))为MSVC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用GCC,我可以指定 __属性__((格式(printf的,1,2))),告诉这个函数采用的printf的格式说明可变参数的参数编译。

With GCC, I can specify __attribute__((format(printf, 1, 2))) , telling the compiler that this function takes vararg parameters that are printf format specifiers.

在这里我换例如这是在案件非常有帮助vfprintf函数族。我可以有
的extern无效LOG_ERROR(为const char *格式,...)__attribute __((格式(printf的,1,2)));

This is very helpful in the cases where I wrap e.g. the vsprintf function family. I can have extern void log_error(const char *format, ...) __attribute__((format(printf, 1, 2)));

和每当我调用这个函数,GCC将检查的种类和数量的参数符合给定的格式说明,因为它会像printf,并发出警告,如果没有。

And whenever I call this function, gcc will check that the types and number of arguments conform to the given format specifiers as it would for printf, and issue a warning if not.

请问在Microsoft C / C ++编译器也有类似的东西吗?

Does the Microsoft C/C++ compiler have anything similar ?

推荐答案

当启用-Wformat当GCC检查格式说明,VC ++就没有这样的检查,即使是标准功能,所以没有等效于此 __ __属性因为没有相当于-Wformat。

While GCC checks format specifiers when -Wformat is enabled, VC++ has no such checking, even for standard functions so there is no equivalent to this __attribute__ because there is no equivalent to -Wformat.

我认为微软对C ++的重点(通过保持符合ISO标准C ++的,而只有支持C89证明)可能部分为什么VC ++没有格式说明检查的原因;用C ++使用< iostream的方式> 格式说明是不必要的。

I think Microsoft's emphasis on C++ (evidenced by maintaining ISO compliance for C++ while only supporting C89) may be in part the reason why VC++ does not have format specifier checking; in C++ using <iostream> format specifiers are unnecessary.

这篇关于__attribute __((格式(printf的,1,2)))为MSVC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆