如何检测“严格别名”在编译时? [英] How to detect 'strict aliasing' at compile time?

查看:114
本文介绍了如何检测“严格别名”在编译时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

严格别名优化需要从源头$ C特殊照顾$ C,SA使用指针类型转换的联合来代替。有没有办法使用preprocessor指令检测(#的if / else)编译器是否正在试图做这样的优化?

'Strict aliasing' optimization needs special care from the source code, s.a. using a union instead of pointer casts. Is there a way to detect using preprocessor directives (#if/else) whether the compiler is trying to do such optimizations?

我要维护旧的和非严格-aliasing- prepared code处理器和不关心的编译器路径。这似乎更快。

I would like to maintain the old and non-strict-aliasing-prepared code path for processors and compilers that don't care. It seems faster.

编辑: GCC predefined宏似乎没有对任何走样。换句话说,我最关心的4.x版的gcc,而且在一般的解决方案(这似乎不存在)。

GCC predefined macros does not seem to have anything about aliasing. In other words, I'm most interested on gcc 4.x, but also in a general solution (which does not seem to exist).

推荐答案

完全依赖于实现的 - 你需要检查的文档为您特定的编译器(S)。并询问这样的问题的时候,它提到在编译器(S)使用的是一个好主意。

Completely implementation dependant - you need to check the docs for your specific compiler(s). And when asking questions like this, it's a good idea to mention which compiler(s) you are using.

一个半便携的方式做,这是从你的Makefile - 定义不同的目标别名和放大器;非混淆版本,并定义自己的STRICT_ALIASING(或其他)的别名版本preprocessor象征。

A semi-portable way to do this is from your Makefile - define different targets for aliased & unaliased versions and define your own STRICT_ALIASING (or whatever) preprocessor symbol for the aliased version.

这篇关于如何检测“严格别名”在编译时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆