zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    mybatis连接MySQL8.0出现的问题
    zqsb项目中发现没有getMSSVideoList
    idea快速实现接口的方法
    鸟枪换炮---IDEA
    IDEA的使用---常用的快捷键
    MQ消息队列
    token的主要用法?
    oracle中游标的使用
    乐观锁和悲观锁
    分布式系统的事务控制
  • 原文地址:https://www.cnblogs.com/liujx2019/p/11978504.html
Copyright © 2011-2022 走看看