Inconsistent structure/union declaration (size mismatch)

An inconsistent data declaration was found.

In this case, the same name was declared as a structure or union in two compilation units, but the size of the types did not match. Usually this results from inconsistent use of packing options.

ID

Observation

Description

1

Definition

The first definition

2

Definition

The second definition

Example

file1.c:

#include <stdio.h>

// Declaration is processed here under normal packing rules
typedef struct MyPackedData
{
    char Data1;
    long Data2;
} st;

extern void SetData2(st *mystruct, long val);

int main(int argc, char **argv)
{
    st x;
    x.Data1 = 'a';
    x.Data2 = 2;

    printf("before call to SetData2(&x, 3), x.Data2=%d\n", x.Data2);

    SetData2(&x, 3);

    printf("after call to SetData2(&x, 3), x.Data2=%d\n", x.Data2);
    return 0;
}
        
file2.c:
          
    #pragma pack(push)  /* push current alignment to stack */
    #pragma pack(1)     /* set alignment to 1 byte boundary */

    // Declaration is processed here under pack(1) rules
    typedef struct MyPackedData
    {
        char Data1;
        long Data2;
    } st;

    #pragma pack(pop)   /* restore original alignment from stack */

    void SetData2(st *mystruct, long val) {
        mystruct->Data2 = val;
    }
        

Copyright © 2010, Intel Corporation. All rights reserved.