【问题标题】:warning: too many arguments for format警告:格式参数过多
【发布时间】:2014-11-24 16:41:04
【问题描述】:
#include<stdio.h>
#include<errno.h>
#include<error.h>
#include<stdlib.h>

#define clean_errno() (errno == 0 ? "None" : strerror(errno))
#define DEBUG_ERROR(M,...) fprintf(stderr, "[ERROR] (%s:%d: (error: %s)) M \n", __FILE__, __LINE__, clean_errno(),##__VA_ARGS__)

int main()
{
   int test =10;
   DEBUG_ERROR("Test variable %s = %d.\n","test",test);
   return 0;
}

关于如何使用调试宏修复以下警告的任何想法...

warn.c:12:4:警告:格式 [-Wformat-extra-args] 的参数过多

【问题讨论】:

  • 请注意,您的宏使用 gcc 扩展 , ## 构造。

标签: c compiler-warnings


【解决方案1】:

你的宏应该是:

#define DEBUG_ERROR(M,...) fprintf(stderr, "[ERROR] (%s:%d: (error: %s)) " M " \n", __FILE__, __LINE__, clean_errno(),##__VA_ARGS__)

请注意,M 现在不在引号中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-13
    • 2011-05-24
    相关资源
    最近更新 更多