__printflike__修饰符 [英] __printflike__ modifier

查看:480
本文介绍了__printflike__修饰符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

"__ printflike__修饰符"到底是什么?这个术语是什么意思?

what is "__printflike__ modifier" exactly? what does this term mean?

推荐答案

猜测它告诉编译器您所使用的函数采用[anything, ] format, ...形式的参数,其中format, ...部分看起来像printf. __printflike__属性使编译器可以针对字符串格式测试参数列表中的类型.当您编写类似log(format, ...)的函数并使用vsprintf在将字符串发送到某些特殊的日志接口之前,使用vsprintf将格式化工作从属于常规的标准库函数时,就会出现这种情况.

At a guess it tells the compiler you're using that a function takes arguments in the form [anything, ] format, ... where the format, ... part look like the arguments to printf. The __printflike__ attribute lets the compiler test the types in the argument list against the string format. This comes up when you write a function like log(format, ...) and use vsprintf to subordinate the formatting work to the usual standard library functions before sending the string to some special log interface.

如果您使用的是GCC,则它可能是项目中的#define,例如:

If you are using GCC then it is probably a #define in your project something like:

#define __printflike__ __attribute__((format(printf, 1, 2)))

1, 2表示format, ...出现在位置1和2.

Where 1, 2 means that format, ... appear in positions 1 and 2.

这篇关于__printflike__修饰符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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