Search code examples
ceclipseeclipse-cdt

Getting syntax errors "type XXX could not be resolved" in eclipse CDT while defining union


I'm getting a syntax error "type XXX could not be resolved" while defining union and this error won't show up on other IDE like VC++. For example, a union is defined below:

typedef union{
    struct {
    int data1;
    int data2;
    int data3;
    } dataField;
    int dataBuffer[sizeof(dataField)];
};

A syntax errors happened.

type 'dataField' could not be resolved

By googling this I found the cause might be the difference between indexers used by eclipse CDT and other IDEs. However, this code still compiles without error. Could someone give a more specific suggestion to deal with this error message? Thanks.


Solution

  • How about:

    typedef struct
    {
       int data1;
       int data2;
       int data3;
    } MyData;
    
    typedef union
    {
       MyData dataField;
       int dataBuffer[sizeof(MyData)];
    } MyUnion;
    

    Not sure, but maybe this will work:

    typedef union
    {
       struct DataStruct
       {
          int data1;
          int data2;
          int data3;
       } dataField;
       int dataBuffer[sizeof(struct DataStruct)];
    };