Ofa
Ofa

Reputation: 67

"Error #119: cast to type <..> is not allowed" when using armcc

I'm trying to compile an existed project (which was designed for gcc) with armcc. For some reason I get the #119 error for the following casting:

(keyCert)(pCertHeader->flags)

I find it very odd because the flags variable is from type uint32_t, and keyCert type is actually uint32_t.

typedef union { 
        struct {
                uint32_t      a:4;
                uint32_t      b:28;
        }c;
        uint32_t      d;
} keyCert;

What could be the reason for this behavior? Note that I was able to compile it with gcc. Thanks!

Upvotes: 1

Views: 8241

Answers (1)

user7771338
user7771338

Reputation: 185

I find it very odd because the flags variable is from type uint32_t, and keyCert type is actually uint32_t.

Wrong, keyCert type is union {...}. Compiler doesn't know if you store struct c or uint32_t d in keyCert, so compiler cannot assume it is uint32_t. The reason GCC possibly doesn't throw any errors is because it is compiler extension. ISO C forbids this type of casting.

Even in GCC if you compile it using C99 strict mode, you will get the following message:

warning: ISO C forbids casts to union type [-Wpedantic]

Upvotes: 2

Related Questions