我使用一个代码,我将枚举*转换为int*.像这样的东西:
enum foo { ... }
...
foo foobar;
int *pi = reinterpret_cast<int*>(&foobar);
Run Code Online (Sandbox Code Playgroud)
在编译代码(g ++ 4.1.2)时,我收到以下警告消息:
dereferencing type-punned pointer will break strict-aliasing rules
Run Code Online (Sandbox Code Playgroud)
我用Google搜索了这条消息,发现只有在严格的别名优化打开时才会发生这种情况.我有以下问题:
是的,我实际上需要这种别名.