struct and union name collision

Viewed 701

I wrote a simple test program and tried to use this:

union FLT { ... };
struct FLT { ... };

But compiler complained about naming collision.

Since in C you need to use struct and union befor your tag name, why would they collide?

I mean when we want to declare a variable of type stuct FLT named num we'd use

struct FLT num;

and when we want to use a variable named diffnum of type union FLT we'd use

union FLT diffnum;

So why couldn't compiler differentiates them?

BTW I tested both MinGW and VC, if you need to know.

UPDATE

union FLOAT {
        float value;
        unsigned int bits;
        unsigned char bytes[4];
};
struct FLOAT {
        unsigned int sign;
        unsigned int exponent;
        unsigned int significand;
};
union FLOAT num;
struct FLOAT num_parts;

I was using this code to do some floating point arithmetic tests.

1 Answers
Related