您的位置:首页 > 编程语言 > C语言/C++

C语言中不同类型的指针互相转换的注意点

2016-04-23 10:24 1031 查看
为什么写本文?
之所以想起来写这篇文章,是因为最近的项目代码频频报出“break strict-aliasing rules”相关的warnning信息,追其原因就是因为不同类型的指针之间的强转引起的。我相信大家平日或多或少写过本文出现的代码,甚至有时候会因这样的trick而感到兴奋,因为很多情况下,这样的代码运行结果是没有问题的。
本文就不同类型的指针之间的转化做个比较详实的阐述:什么情况下,它们之间可以转化而不会引起问题,而又在什么情况下,强转会发生意想不到的结果呢? 关于这一切标准又是怎么说的呢? 这都是本文需要搞清楚的问题。

参考连接:
Why is this implicit conversion (between different pointer types) valid?
Casting one struct pointer to other - C
Converting a pointer to different type in C
Is This “Type Punning” Well-Defined?》
Pointers in C, Part III: The Strict Aliasing Rule

Understanding Strict Aliasing
Understanding C/C++ Strict Aliasing
Strict aliasing in C
strict aliasing
Type-punning and the strict aliasing rule
ARM: Efficient C for ARM: Pointer Aliasing
GCC, strict aliasing, C99
GCC strict aliasing
About the C ++ aliasing, dexterous optimization and mean bugs
strict aliasing
Strict aliasing...
Strict Aliasing,神坑?
C/C++ Strict Alias 小记
The Strict Aliasing Situation is Pretty Bad
《Type Punning, Strict Aliasing, and Optimization

gcc strict-aliasing是什麼?
GCC:strict-aliasing rules
Restricting what you can do
Strict aliasing and std::vector
Solving the gcc 4.4 strict aliasing problems
C pointer aliasing violiations and aggressive compiler optimizations
Type punning, aliasing, unions, strict-aliasing, oh my!
C99 Strict Aliasing Rules and Packed Streams
What is the strict aliasing rule?
Solving the gcc 4.4 strict aliasing problems
Type-punning and the strict aliasing rule
GCC strict aliasing pitfall
How to Access Safely Unaligned Data

Demystifying The Restrict Keyword
RESTRICT, Keyword for Low-Level Pointer Efficiency
The restrict keyword in C programming
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: