如何在C中使用单个赋值定义多个#define

问题描述 投票:0回答:1

我发现了有关How do I #define multiple values C / C++的一些相关问题。但是那不是我想要的。相反,我想做相反的事情。

我们可以简单地分配这样的内容

int a,b,c,d,e;
a = b = c = d = e = 5;
printf("Value %d",e);

但是我正在寻找的是如何在给定修复值的情况下将下面的定义合并到一行中。

#define SIZE_OF_NODE_ADD   4
#define SIZE_OF_KEY_ADD    4
#define SIZE_OF_ID_ADD     4
#define SIZE_OF_PW_ADD     4

可以这样做吗?类似于

#define SIZE_OF_NODE_ADD = SIZE_OF_KEY_ADD = SIZE_OF_ID_ADD = SIZE_OF_PW_ADD = 4
/* The syntax is wrong, I just emphasize for easier understanding what I am looking for*/  
c c-preprocessor
1个回答
0
投票

在C标准中,预处理器语句由换行符终止,因此您必须执行:

#define SIZE_OF_NODE_ADD   4
#define SIZE_OF_KEY_ADD    4
#define SIZE_OF_ID_ADD     4
#define SIZE_OF_PW_ADD     4

不允许使用多重定义语句。(甚至很难阅读)

© www.soinside.com 2019 - 2024. All rights reserved.