有没有办法使用#define 指令来创建常量结构?
Is there a way to use the #define directive to create a constant struct?
假设我有这个结构
typedef struct
{
int AM;
char* name, surname;
}Item;
我想用 AM = -1 和 NULL name/surname 定义常量 NULLitem。有没有办法用#define 做到这一点?
#define NULLitem (const Item){ .AM = -1, .name = NULL, .surname = NULL }
那是 C99 compound literal。
假设我有这个结构
typedef struct
{
int AM;
char* name, surname;
}Item;
我想用 AM = -1 和 NULL name/surname 定义常量 NULLitem。有没有办法用#define 做到这一点?
#define NULLitem (const Item){ .AM = -1, .name = NULL, .surname = NULL }
那是 C99 compound literal。