type enum {
enum_0,
enum_1,
} ENUM_NAME;
int main()
{
ENUM_NAME a = enum_0;
int *p1 = (int *)(&a); //(1)
int *p2 = &a; //(2)
return 0;
}
(2) -- will have warning like
warning: initialization from incompatible pointer type
(1) -- will have warning like
warning: dereferencing type-punned pointer will break strict-aliasing rules
resolution: there are some ways to resolve it, but i think this is better
type enum {
enum_0,
enum_1,
} __attribute__((__may_alias__)) ENUM_NAME;
refer
http://blog.worldofcoding.com/2010/02/solving-gcc-44-strict-aliasing-problems.html
enum_0,
enum_1,
} ENUM_NAME;
int main()
{
ENUM_NAME a = enum_0;
int *p1 = (int *)(&a); //(1)
int *p2 = &a; //(2)
return 0;
}
(2) -- will have warning like
warning: initialization from incompatible pointer type
(1) -- will have warning like
warning: dereferencing type-punned pointer will break strict-aliasing rules
resolution: there are some ways to resolve it, but i think this is better
type enum {
enum_0,
enum_1,
} __attribute__((__may_alias__)) ENUM_NAME;
refer
http://blog.worldofcoding.com/2010/02/solving-gcc-44-strict-aliasing-problems.html