简体   繁体   English

警告:格式参数过多

[英]warning: too many arguments for format

#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;
}

Any ideas on how to fix the following warning with the debug macro... 有关如何使用调试宏修复以下警告的任何想法...

warn.c:12:4: warning: too many arguments for format [-Wformat-extra-args] warn.c:12:4:警告:格式[-Wformat-extra-args]的参数过多

Your macro should be: 您的宏应为:

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

Note that M is not in quotes now. 请注意, M现在不在引号中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM