tag:blogger.com,1999:blog-14489808.post7712689692514569823..comments2023-10-11T19:25:42.224+08:00Comments on $4 blog: C++ Programming: Call by Reference/Value/Pointer and const_cast$4http://www.blogger.com/profile/05027047996196141367noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-14489808.post-10098020687082991922009-11-13T17:57:18.790+08:002009-11-13T17:57:18.790+08:00main::value 是一個 alias, compiler (g++ 4.3.4) 會替換成 i...main::value 是一個 alias, compiler (g++ 4.3.4) 會替換成 integral literal,但是依然會在 Stack 中配置此變數供人使用。因此你可以對其寫入 (as memory/stack),惟讀取時依然讀 integral literal.<br /><br />其他討論請見 <a href="http://hackingthursday.wikidot.com/2009-11-12" rel="nofollow">http://hackingthursday.wikidot.com/2009-11-12</a>Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-14489808.post-51283691542535436552009-11-13T17:08:39.103+08:002009-11-13T17:08:39.103+08:00Because this is undefined behavior.
From ISO/IEC ...Because this is undefined behavior.<br /><br />From ISO/IEC 14882 [dcl.type.cv]<br /><br />Except that any class member declared mutable can be modified, any attempt to modify a const object during its lifetime results in undefined behavior.czchenhttps://www.blogger.com/profile/06192886717013363414noreply@blogger.comtag:blogger.com,1999:blog-14489808.post-15818407955257012492009-11-13T12:59:14.453+08:002009-11-13T12:59:14.453+08:00I was going to post my comment here, but it got to...I was going to post my comment here, but it got <a href="http://fsfoundry.org/codefreak/2009/11/13/what-happens-when-we-lie-to-the-compiler/" rel="nofollow">too long</a>...fr3@Khttps://www.blogger.com/profile/08991591010748622228noreply@blogger.com