Search code examples
cgccstructgcc-warning

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


I have the following struct

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

when I try to compile my code I get this warning from gcc

warning: unnamed struct/union that defines no instances

followed by a bunch of errors caused by VMCS being undefined. The code that precedes this is very innocuous, consisting of including stdint.h and a number of #define entries. It does not seem like those could cause errors that would interfere with the struct.


Solution

  • ... and a number of #define entries

    Apparently you defined VMCS as a macro with empty replacement list. Your code is seen by the compiler as

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

    Hence the warning.