• 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

  • 相关阅读:
    剑指offer-二进制中1的个数
    [SHOI 2017] 分手是祝愿
    [SCOI 2010] 字符串
    [BZOJ 2653] middle
    [APIO 2015] 雅加达的摩天楼
    [NOI 2015] 品酒大会
    [SDOI 2015] 星际战争
    [Codeforces 715C] Digit Tree
    [TJOI 2018] 智力竞赛
    [CTSC 2018] 混合果汁
  • 原文地址:https://www.cnblogs.com/liujx2019/p/11978504.html
Copyright © 2020-2023  润新知