gcc 警告 "unnamed struct/union that defines no instances",但该结构确实有一个名称

gcc warns about "unnamed struct/union that defines no instances", but the struct does have a name

我有以下结构

typedef struct VMCS
{
    uint32_t revision;
    uint32_t abortValue;
} __attribute__ ((packed)) VMCS;

当我尝试编译我的代码时,我收到来自 gcc 的警告

warning: unnamed struct/union that defines no instances

接着是VMCS未定义导致的一堆错误。在此之前的代码非常无害,包括 stdint.h 和许多 #define 条目。这些似乎不会导致会干扰结构的错误。

... and a number of #define entries

显然您将 VMCS 定义为替换列表为空的宏。您的代码被编译器视为

typedef struct
{
    uint32_t revision;
    uint32_t abortValue;
} __attribute__ ((packed));

因此警告。