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与 ...
随机推荐
- EOS基础全家桶(五)钱包管理
简介 本篇我们将会学习EOS自带的命令行钱包的使用方法,我们将会使用cleos来控制keosd服务对本地钱包进行管理. 虽然现在市面上已经有很多支持EOS的钱包了,有Web钱包,有app钱包,还有浏览 ...
- redis 练习
redis-server启动服务 redis-cli 进入redis redis 常用的keys键操作: exists key ---检查key是否存在 del key1 key2 ---删除指定的 ...
- Q - Queue HDU - 5493(树状树组维护区间前缀和 + 二分找预留空位)
Q - Queue HDU - 5493 Problem Description NNN people numbered from 1 to NNN are waiting in a bank for ...
- P1004 方格取数(四维dp)
P1004 方格取数 思路如下 这题是看洛谷大佬的思路才写出来的,所以我会把大佬的思路展示如下: 1⃣️:我们可以找到一个叫思维dp的东西,dp[i][j][k][l],其中前两维表示一个人从原点出发 ...
- 用Fiddler抓取手机APP数据包
Fiddler下载地址 1.允许远程连接 2.允许监听https 3.重启Fiddler 这步很重要,不要忘了 4.手机配置 用ipconfig命令查询当前PC的局域网IP 将手机连接上同一个WIFI ...
- Redis 笔记(四)—— SET 常用命令
常用命令 命令 用例和描述 SADD SADD key item [item ...] —— 将一个或多个元素添加到集合中,返回添加的数量 SREM SREM key item [item ...] ...
- 部署MYSQL高可用集群
mysql-day08 部署MYSQL高可用集群 u 集群架构 ...
- c++类模板之分文件编写问题及解决
我们在实际项目中一般习惯头文件(.h)和源文件(.cpp)分开写,这样做的好处良多,但是如果遇到了类模板,这样可能会有一点儿问题. 我们通过一个例子来看: person.h: #pragma once ...
- javascript - 所有的视图属性和方法(offsetHeight、clientHeight、scrollHeight、innerHeight等)
注意:本文只简单的介绍了各个视图的属性和方法.如果想要知道兼容性或者更多,请至文章底部参考链接处. 本文内容分为五大部分: Window视图属性 innerHeight 和 innerWidth ou ...
- Lua 5.3 -- SOL2.0 用户指南 【2】
系列教程指南[1] 注意 在你学习了sol的基础知识之后,建议你如果认为某些东西可以运行,你应该尝试一下.它可能会运行! 以下所有代码均可在sol2教程示例中找到. 断言/先决条件 The imple ...