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

为什么写本文?

之所以想起来写这篇文章,是因为最近的项目代码频频报出“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

What is the Strict Aliasing Rule and Why do we care?

 

 

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值