遇君阁

前不见古人,后不见来者
念天地之悠悠,独怆然而涕下

  VC知识库BLOG :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 登录 ::
  26 随笔 :: 8 文章 :: 53 评论 :: 0 Trackbacks
<2008年3月>
2425262728291
2345678
9101112131415
16171819202122
23242526272829
303112345

留言簿(0)

随笔分类

随笔档案

文章分类

文章档案

相册

相关链接

搜索

最新评论

阅读排行榜

评论排行榜

2008年3月5日 #

constant folding

A compiler optimisation technique where constant subexpressions are evaluated at compile time. This is usually only applied to built-in numerical and boolean operators whereas partial evaluation is more general in that expressions involving user-defined functions may also be evaluated at compile time.

const propagation

Constant propagation is the process of substituting the values of known constants in expressions at compile time. Such constants include those defined above, as well as intrinsic functions applied to constant values. Consider the following pseudocode:

 int x = 14;
 int y = 7 - x / 2;
 return y * (28 / x + 2);

Applying constant propagation once yields:

 int x = 14;
 int y = 7 - 14 / 2;
 return y * (28 / 14 + 2);


My Misunderstanding: Previously I thought Const Folding will store different const vairables with same value in the same memory at run time.
But I'm wrong, the actual case is:

Const Folding doesn't mean that the different const vairable with the same value in different compilaton unit will be
stored in the same memory. I can give an example to show that. By default, const objects are local to the file
in which they are defined, so it is legal to put their definition in a header file.There is one important implication of
this behavior. When we define a const in a header file, every source file that includes that header has its own const
variable with the same name and value. But they are not saved in the same storage.


发表于 2008-03-05 14:51 遇君阁 阅读(583) | 评论 (0)编辑 收藏