c++ - “编译过程中若发现使用常量则直接以符号表中的值替换”与“const 可以节省空间,避免不必要的内存分配”是否矛盾?
大家讲道理
大家讲道理 2017-04-17 15:36:57
0
1
644
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
Ty80

The two statements you used to compare are both debatable.

The compiler may fold compile-time constants into instructions and not allocate memory on the stack at all. It is also possible to combine multiple identical constants into one and place them in the data segment. Making such a decision requires analyzing the complete code, and the factors that affect the decision include more than just define and const.

tldr: Don’t guess the compilation results by looking at the code. The only reliable comparison method is objdump.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!