标准在哪里谈到混叠? [英] Where does the standard talk about aliasing?

查看:98
本文介绍了标准在哪里谈到混叠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++标准中,它谈到别名?我看着ToC,没有看到别名这个词。我试图查看一个定义规则(3.2),搜索'alias'没有结果。我在一个损失,它可能是。我在寻找内存别名

Where in the C++ standard does it talk about aliasing? I looked at the ToC and saw no mention of the word 'alias'. I tried to look in the one definition rule (3.2) and a search of 'alias' had no results there. I'm at a loss where it may be. I'm looking for memory aliasing

推荐答案

别名主要在§3.10[basic.lval] / 10:

Aliasing is mainly discussed in §3.10[basic.lval]/10:


如果程序试图通过除了
之外的glvalue访问对象的存储值,那么行为是未定义的: 52


  • 对象的动态类型,

  • a对象动态类型的cv限定版本

  • 类似于对象动态类型的类型(如4.4中定义)

  • 类型是对应于对象的动态类型的有符号或无符号类型

  • 类型是对应于动态类型的cv限定版本的有符号或无符号类型

  • 一个聚合或联合类型,在其元素或非
    静态数据成员中包含上述类型之一(包括递归子元素
    的元素或非静态数据成员,或包含union),

  • 类型是动态类型的对象,

  • a char unsigned char
  • the dynamic type of the object,
  • a cv-qualified version of the dynamic type of the object,
  • a type similar (as defined in 4.4) to 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 elements or non- static data members (including, recursively, an element or non-static data 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.

52)此列表的目的是指定对象可能或不可以混淆的情况。 / p>

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

例如,

int x = 1;
*(char*)(&x);     // (implementation-)defined
*(unsigned*)(&x); // (implementation-)defined
*(float*)(&x);    // undefined







The following mentions may also be interesting.

§5.17[expr.ass] / 8

§5.17[expr.ass]/8


存储在对象中的另一个对象从另一个对象访问,该对象以任何方式与第一个对象的
的存储重叠,则重叠应该是精确的,并且两个对象应具有相同的类型,否则
行为是未定义。 [注意:此限制适用于左侧和右侧之间的关系
的赋值操作;它不是关于如何可以在
通用别名中分配任务的目标的声明。见3.10。 - 结束注释]

If the value being stored in an object is accessed from another object that overlaps in any way the storage of the first object, then the overlap shall be exact and the two objects shall have the same type, otherwise the behavior is undefined. [ Note: This restriction applies to the relationship between the left and right sides of the assignment operation; it is not a statement about how the target of the assignment may be aliased in general. See 3.10. — end note ]

§17.6.4.9[res.on.arguments] / 1 pt 3:

§17.6.4.9[res.on.arguments]/1 pt 3:


如果函数参数绑定到右值引用参数,则实现可以假定
此参数是对此参数的唯一引用论据。 ... [
实现可以自由地优化掉别名检查,如果参数是
,则可能需要别名检查。]

If a function argument binds to an rvalue reference parameter, the implementation may assume that this parameter is a unique reference to this argument. … [The implementation is free to optimize away aliasing checks which might be needed if the argument was an lvalue.]


$ b b

§26.6.2[valarray.syn] / 2:

§26.6.2[valarray.syn]/2:


valarray 数组类被定义为没有某些形式的别名,因此允许对
操作优化这些类。

The valarray array classes are defined to be free of certain forms of aliasing, thus allowing operations on these classes to be optimized.

< valarray> 的其余部分还讨论了如何实现该类以避免数据别名。

and the rest of <valarray> also discusses how the class should be implemented to avoid data aliasing.

这篇关于标准在哪里谈到混叠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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