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)))的更多相关文章

  1. __attribute__((format(printf, a, b)))

    最近,在看libevent源码,第一次看到__attribute__((format(printf, a, b)))这种写法.因此,在这里记录下用法. 功能:__attribute__ format属 ...

  2. printf参数的问题

    根据前面的某一篇的文章,可以清楚的看到:对于每一个函数,通过这个函数的[ebp+x]就可以直接访问到它调用的时候传进来的形参的值,通过[ebp-x]就可以直接访问它的局部变量. 所以printf这个函 ...

  3. C: printf参数执行顺序与前置后置自增自减的影响

    起源: 今天在了解副作用side-effect的过程中,看到了下面的网页,把我带到了由printf引起的一系列问题,纠结了一整天,勉强弄懂. 第一个代码没什么好解释的.而第二个printf(" ...

  4. printf("%d",5.01)和printf("%f",5)的输出结果

    printf(); printf("%d\n",5.01); printf(); printf(.f); 输出结果: 看到结果,会感觉非常奇怪.1处怎么会输出0呢?2又为何会显示这 ...

  5. printf("%*s\n", 1, ""); 使用"printf();" 的格式化输出动态制定等宽度输出。

    #include <stdio.h> #include <string.h> int main() { const char the_text[] = "this i ...

  6. python定义函数以及参数检查

    (转自廖雪峰网站) 函数定义 在Python中,定义一个函数要使用def语句,依次写出函数名.括号.括号中的参数和冒号:,然后,在缩进块中编写函数体,函数的返回值用return语句返回. 我们以自定义 ...

  7. OpenJDK源码研究笔记(一)-参数检查&抛出带关键错误提示信息的异常

    OpenJDK源码研究笔记系列文章,是我在阅读OpenJDK7源码的过程中的一些体会.收获.看法. 把研究过程中的成长和收获一点点地整理出来,是对自己研究学习的一个小结,也有可能给学习Java的一些同 ...

  8. 汇编中call printf参数压栈时错误理解

    EAX, ECX,EDX,EBX均可以32bit,16bit,8bit访问,如下所示: <-------------------EAX------------------------>|& ...

  9. C语言如何在可变参数函数中使用printf?

    我要将printf外面再包上一层:void fun(const char* fmt,...) {........printf(fmt,...);........}这种函数怎么写? 对比下printf与 ...

随机推荐

  1. Mac LaTex中文环境搭建

    为了在博客上写公式,折腾了一晚上Mac上的LaTex的环境搭建,本文对步骤进行记录. 系统:Mac OSX 10.10.5 软件准备 1) MacTex 2015 Distribution (Tex的 ...

  2. Html,css构建一个对话框,练习201911281028

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...

  3. localStorage应用(写的时间缓存在本地浏览器)

    最近用了下localStorage,于是想记录加深下映象: 有关更详细的介绍,可以去看https://www.cnblogs.com/st-leslie/p/5617130.html: 我这引用了这个 ...

  4. C 旅店

    时间限制 : - MS   空间限制 : - KB  评测说明 : 1s,256m 问题描述 一条笔直的公路旁有N家旅店,从左往右编号1到N,其中第i家旅店的位置坐标为Xi.旅人何老板总在赶路.他白天 ...

  5. docker 容器容器之间网络通信 docker-compose.yaml 配置固定ip

    1.创建自己的桥接网络 $ docker network create --subnet=172.18.0.0/16 mynetwork 2.docker-compose.yaml 文件格式demo ...

  6. css怪异盒模型和弹性盒布局(flex)详解及其案例

    一.怪异盒模型 怪异盒模型的属性是box-sizing,他有两个属性值: 1.content-box 这是由 CSS2.1 规定的宽度高度行为.宽度和高度分别应用到元素的内容框.在宽度和高度之外绘制元 ...

  7. MySQL学习之路2-数据库and数据表的基本操作

    数据库基本操作 查看.选择数据库: show databases; use <databasename>; 创建数据库:create database <dbname> cha ...

  8. css--->圆角设置

    1.为元素添加四个相同的圆角: 语法结构:border-radius:r: r为圆角的半径大小 eg:如下样式,给元素添加四个圆角为10px   代码如下: <!DOCTYPE html> ...

  9. golang 在 Mac , Linux , Windows 下交叉编译详解

    一. 前言 Golang 支持交叉编译, 在一个平台上生成然后再另外一个平台去执行. 而且编译的工具[build]这个工具是Golang 内置的,不需要你去下载第三方的包啥的,贼方便. 二. 交叉编译 ...

  10. 虚拟机VMware 安装后虚拟机网卡与主机网卡数据交换关系

    安装好虚拟机以后,在网络连接里面可以看到多了两块网卡: 其中VMnet1是虚拟机Host-only模式的网络接口,VMnet8是NAT模式的网络接口,这些后面会详细介绍.在VMware Worksta ...