printf 参数检查 __attribute__((format(printf, 1, 2)))
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 have extern void log_error(const char *format, ...) __attribute__((format(printf, 1, 2)));
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.
Does the Microsoft C/C++ compiler have anything similar ?
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.
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.
https://stackoverflow.com/questions/2354784/attribute-formatprintf-1-2-for-msvc
printf 参数检查 __attribute__((format(printf, 1, 2)))的更多相关文章
- __attribute__((format(printf, a, b)))
最近,在看libevent源码,第一次看到__attribute__((format(printf, a, b)))这种写法.因此,在这里记录下用法. 功能:__attribute__ format属 ...
- printf参数的问题
根据前面的某一篇的文章,可以清楚的看到:对于每一个函数,通过这个函数的[ebp+x]就可以直接访问到它调用的时候传进来的形参的值,通过[ebp-x]就可以直接访问它的局部变量. 所以printf这个函 ...
- C: printf参数执行顺序与前置后置自增自减的影响
起源: 今天在了解副作用side-effect的过程中,看到了下面的网页,把我带到了由printf引起的一系列问题,纠结了一整天,勉强弄懂. 第一个代码没什么好解释的.而第二个printf(" ...
- printf("%d",5.01)和printf("%f",5)的输出结果
printf(); printf("%d\n",5.01); printf(); printf(.f); 输出结果: 看到结果,会感觉非常奇怪.1处怎么会输出0呢?2又为何会显示这 ...
- printf("%*s\n", 1, ""); 使用"printf();" 的格式化输出动态制定等宽度输出。
#include <stdio.h> #include <string.h> int main() { const char the_text[] = "this i ...
- python定义函数以及参数检查
(转自廖雪峰网站) 函数定义 在Python中,定义一个函数要使用def语句,依次写出函数名.括号.括号中的参数和冒号:,然后,在缩进块中编写函数体,函数的返回值用return语句返回. 我们以自定义 ...
- OpenJDK源码研究笔记(一)-参数检查&抛出带关键错误提示信息的异常
OpenJDK源码研究笔记系列文章,是我在阅读OpenJDK7源码的过程中的一些体会.收获.看法. 把研究过程中的成长和收获一点点地整理出来,是对自己研究学习的一个小结,也有可能给学习Java的一些同 ...
- 汇编中call printf参数压栈时错误理解
EAX, ECX,EDX,EBX均可以32bit,16bit,8bit访问,如下所示: <-------------------EAX------------------------>|& ...
- C语言如何在可变参数函数中使用printf?
我要将printf外面再包上一层:void fun(const char* fmt,...) {........printf(fmt,...);........}这种函数怎么写? 对比下printf与 ...
随机推荐
- Android 数据库框架 DBFlow 的使用
原文首发于微信公众号:jzman-blog,欢迎关注交流! DBFlow 是一个基于注解处理器开发的使用方便的 ORM Android 数据库,该库简化了很多多余的代码,并且提供了好用的 API 来处 ...
- A 拜访奶牛
时间限制 : - MS 空间限制 : 65536 KB 评测说明 : 时限1000ms 问题描述 经过了几周的辛苦工作,贝茜终于迎来了一个假期.作为奶牛群中最会社交的牛,她希望去拜访N(1< ...
- Codeforces Round #629 (Div. 3)
A. Divisibility Problem time limit per test 1 second memory limit per test 256 megabytes input stand ...
- C. Yet Another Walking Robot Round #617 (Div. 3)()(map + 前后相同状态的存储)
C. Yet Another Walking Robot time limit per test 1 second memory limit per test 256 megabytes input ...
- Vertica的这些事(三)——Vertica中实现Oracle中的ws_concat功能
vertica中没有类似Oracle中的ws_concat函数功能,需要开发UDF,自己对C++不熟悉,所有只有想其他方法解决了. 上代码: SELECT node_state, MAX(DECODE ...
- HDU1398:Square Coins(DP水题)
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- Windows10系统常规优化及分析(批处理)
对于Win7来说,Win10除了UI的变动外,微软还根据用户体验做了一些功能的增强和更改,在我看来,Win10本身启动的服务都是为了系统运作更加完美而增加的,但是对于很多人来说,Win10的很多功能很 ...
- Java对字母大小写转换
Java对字母大小写转换 1.小写——大写String aa = "abc".toUpperCase(); 2.大写——小写 String bb = "ABC" ...
- Linux利器:使用 gcc 编程C程序
文章更新于:2020-03-23 文章目录 一.手动编译链接单个C源文件 1.创建C源文件 2.编译源文件 3.生成可执行文件 二.手动编译链接多个C源文件 1.创建两个C源文件 2.编译两个源文件 ...
- uni-app的初识(01)
1.什么是uni-app uni-app 是一个使用 Vue.js 开发所有前端应用的框架, 开发者编写一套代码, 可发布到IOS, Android, H5, 以及各种小程序(微信,百度)等多个平台. ...