gpt4 book ai didi

c - 宏返回编译警告中args的定义

转载 作者:太空宇宙 更新时间:2023-11-04 06:20:17 24 4
gpt4 key购买 nike

我有以下代码:

#include <stdio.h>
#include <string.h>

#define ARGS \
struct kk *k, \
struct kk1 *k1 \


struct kk {
int a;
int b;
int (*f)(ARGS);
};

struct kk1 {
char a;
char b;
};


int main(int argc, char *argv[]) {
struct kk pp = {.a = 1};
printf("ddmsgstsssssssr ___(%d)__\n", pp.a);
return 0;
}

当我使用 gcc -o test test.c 构建它时,我收到了以下警告:

test.c:6:9: warning: ‘struct kk1’ declared inside parameter list [enabled by default]
struct kk1 *k1 \
^
test.c:12:11: note: in expansion of macro ‘ARGS’
int (*f)(ARGS);
^
test.c:6:9: warning: its scope is only this definition or declaration, which is probably not what you want [enabled by default]
struct kk1 *k1 \
^
test.c:12:11: note: in expansion of macro ‘ARGS’
int (*f)(ARGS);
^

如何解决这个问题?

最佳答案

要么将 struct kk1 移动到 struct kk 之前,要么向前声明 struct kk1。如果您不想定义结构,则后者更优雅。

#define ARGS \
struct kk *k, \
struct kk1 *k1 \

struct kk1; /* this changed */
struct kk {
int a;
int b;
int (*f)(ARGS);
};

struct kk1 {
char a;
char b;
};

关于c - 宏返回编译警告中args的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36663203/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com