做C89或C ++ 03定义严格别名规则? [英] Do C89 or C++03 define strict aliasing rules?

查看:81
本文介绍了做C89或C ++ 03定义严格别名规则?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过几个断言的C89和C ++ 03严格定义别名规则。但是,我无法找到的标准的特定位。我的理解是,在C99中添加严格别名规则。

I've seen several assertions that C89 and C++03 define strict aliasing rules. I, however, cannot find that particular bit in the standard. My understanding was that strict aliasing rules were added in C99.

推荐答案

在C ++标准03下有以下§3.10[basic.lval] P15

The C++03 standard has the following under §3.10 [basic.lval] p15:

如果一个程序尝试通过其它的左值比以下类型的行为是未定义 48)中的一个来访问对象的存储值:搜索
   - 动态类型的对象,结果的
   - 动态类型的对象,而一个CV限定版搜索
   - 一种类型,它是符号或对应的动态对象的类型无符号类型,结果,
   - 一种类型,它是符号或对应的动态对象的类型的一个cv修饰版本无符号类型,结果,
   - 包括其成员之间的上述类型之一(包括递归,一个子聚集的成员或包含的联合),结果聚合或联合类型
   - 一个类型,是一个(可能CV-限定)基类型的动态类型的对象的,结果,
   - 一个char或unsigned char类型

If a program attempts to access the stored value of an object through an lvalue of other than one of the following types the behavior is undefined48):
— the dynamic type of the object,
— a cv-qualified version of the dynamic type of the object,
— a type that is the signed or unsigned type corresponding to the dynamic type of the object,
— a type that is the signed or unsigned type corresponding to a cv-qualified version of the dynamic type of the object,
— an aggregate or union type that includes one of the aforementioned types among its members (including, recursively, a member of a subaggregate or contained union),
— a type that is a (possibly cv-qualified) base class type of the dynamic type of the object,
— a char or unsigned char type.

脚注:

48)此列表的目的是,以指定在其中一个对象可能会或可能不会被混叠的那些情况。

48) The intent of this list is to specify those circumstances in which an object may or may not be aliased.

本网站还列出了其他标准的部分。

This site also lists the sections in the other standards.

这篇关于做C89或C ++ 03定义严格别名规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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