名可名, 非常名

在调一个题目的过程中发现了一个之前从未意识到的问题.

考虑如下代码

vector<int> a;

int f(int x){
a.push_back(x);
return *a.rbegin();
} a.push_back(0);
a[0]=f(1);

试问最后a[0]的值.

Unique Variable

a variable provides us with named storage that our programs can manipulate.

这里需要指出的是, a[0]是一个返回lvalue的expression, 它是一个variable, 但并是一个unique variable.

(unique variable这个词是我造的, 下面将会解释其含义)

如果一个变量在它的lifetime中都指向 (refer to) 同一storage, 则称其为 unique variable.

Remember That Operands Can Be Evaluated in Any Order

Precedence specifies how the operands are grouped. It says nothing about the order in which the operands are evaluated. In most cases, the order is largely unspecified. In the following expression

int i = f1() * f2();

We know that f1 and f2 must be called before the multiplication can be done. After all, it is their results that are multiplied. However, we have no way of knowing whether f1 will be called before f2 or vice versa.

For operators that do not specify evaluation order, it is an error for an expression to refer to and change the same object. Expressions that do so have undefined behavior.

There are four operators that do guarantee the order in which operands are evaluated: the logical AND (&&) operator, the logical OR (||) operator, the conditional (?

最新文章

  1. selenium获取Cookie操作
  2. DataSnap修改数据ApplyUpdates出现错误:连接繁忙导致另一个命令
  3. 0.1 hint crack
  4. ubuntu maven环境安装配置
  5. 李洪强iOS开发之OC语言BLOCK和协议
  6. android客户端从服务器端获取json数据并解析的实现代码
  7. 《APUE》第三章笔记(4)及习题3-2
  8. ng表单验证,提交以后才显示错误
  9. 【剑指Offer学习】【面试题14 :调整数组顺序使奇数位于偶数前面】
  10. php 中PHP_EOL使用
  11. php基础(六)Include
  12. 安装IPython攻略
  13. EffictiveC++笔记 第3章
  14. C#编辑EXE使用的appSettings节点的Config文件
  15. 优化 Markdown 在 Notepad++ 中的使用体验
  16. Docker Swarm 创建服务
  17. /dev/null与/dev/zero区别
  18. where子查询
  19. UVA-10692 Huge Mods
  20. saltops 安装及相关环境安装

热门文章

  1. bootstrap(关于栅格布局)
  2. 总结js常用函数和常用技巧(持续更新)
  3. STSDB、NDataBase 对象数据库在不同.net framework下无法读取的解决办法
  4. SlidingMenu 侧滑菜单的用法
  5. SQL SERVER 数据库各版本功能对比
  6. Redis学习笔记~Redis事务机制与Lind.DDD.Repositories.Redis事务机制的实现
  7. android px转换为dip/dp
  8. kvm/qemu/libvirt学习笔记 (1) qemu/kvm/libvirt介绍及虚拟化环境的安装
  9. 用java String类的getBytes(String charsetName)和String(byte[] bytes, String charsetName)解决乱码问题
  10. JQuery中$.ajax()方法参数详解 及 async属性说明