__attribute__((format(printf, a, b)))】的更多相关文章

最近,在看libevent源码,第一次看到__attribute__((format(printf, a, b)))这种写法.因此,在这里记录下用法. 功能:__attribute__ format属性可以给被声明的函数加上类似printf或者scanf的特征,它可以使编译器检查函数声明和函数实际调用参数之间的格式化字符串是否匹配.format属性告诉编译器,按照printf, scanf等标准C函数参数格式规则对该函数的参数进行检查.这在我们自己封装调试信息的接口时非常的有用. format的…
With GCC, I can specify __attribute__((format(printf, 1, 2))) , telling the compiler that this function takes vararg parameters that are printf format specifiers. This is very helpful in the cases where I wrap e.g. the vsprintf function family. I can…
简介: 在IOS9.2官方文档中Attributes的描述如下,简单明了: Attributes provide more information about a declaration or type. There are two kinds of attributes in Swift, those that apply to declarations and those that apply to types. 简单来说,就是使用这种规则来对一些方法声明或者类型声明进行一个功能性描述,并且…
本文目录 iOS宏的经典用法 Apple的习惯 __attribute__ iOS宏的经典用法 1.常量宏.表达式宏 #define kTabBarH (49.0f) #define kScreenH [UIScreen mainScreen].bounds.size.height #define isScreenWidthEqual320 (fabs([UIScreen mainScreen].bounds.size.width - 320) < DBL_EPSILON) 2.带参数的宏 //…
转来的: http://www.cnblogs.com/astwish/p/3460618.html __attribute__ 你知多少? GNU C 的一大特色就是__attribute__ 机制.__attribute__ 可以设置函数属性(Function Attribute ).变量属性(Variable Attribute )和类型属性(Type Attribute ). __attribute__ 书写特征是:__attribute__ 前后都有两个下划线,并切后面会紧跟一对原括弧…
经常会用到C的格式化字符串,gcc/clang的扩展,都是可以进行字符串和可变参数的检测,不匹配,就会爆warning. 自己手写的,需要加上一点代码,否则不会进行检测. 1.  可变参数 void my_printf(const char* format, ...) __attribute__ ((format (printf, 1, 2))) 这里的1, 表示format string所在参数的下标(从1开始); 2表示可变参数开始的下标. 2. va_list void my_print(…
GNU C 的一大特色就是__attribute__ 机制.__attribute__ 可以设置函数属性(Function Attribute ).变量属性(Variable Attribute )和类型属性(Type Attribute ). __attribute__ 书写特征是:__attribute__ 前后都有两个下划线,并切后面会紧跟一对原括弧,括弧里面是相应的__attribute__ 参数. __attribute__ 语法格式为:__attribute__ ((attribut…
转自:http://www.cnblogs.com/astwish/p/3460618.html GNU C 的一大特色就是__attribute__ 机制.__attribute__ 可以设置函数属性(Function Attribute ).变量属性(Variable Attribute )和类型属性(Type Attribute ). __attribute__ 书写特征是:__attribute__ 前后都有两个下划线,并切后面会紧跟一对原括弧,括弧里面是相应的__attribute__…
转自:http://www.cnblogs.com/astwish/p/3460618.html GNU C 的一大特色就是__attribute__ 机制.__attribute__ 可以设置函数属性(Function Attribute ).变量属性(Variable Attribute )和类型属性(Type Attribute ). __attribute__ 书写特征是:__attribute__ 前后都有两个下划线,并切后面会紧跟一对原括弧,括弧里面是相应的__attribute__…
转载:http://blog.csdn.net/ithomer/article/details/6566739 1. __attribute__ GNU C的一大特色(却不被初学者所知)就是__attribute__机制. __attribute__可以设置函数属性(Function Attribute).变量属性(Variable Attribute)和类型属性(Type Attribute) __attribute__前后都有两个下划线,并且后面会紧跟一对原括弧,括弧里面是相应的__attr…