→ aoc90058:我好像用到人推文?! Orz...咩~~~~~~~~~ 02/04 00:00
※ 編輯: aoc90058 來自: 59.125.68.140 (02/04 00:12)
=========================================================================
十械之九提及
你也不可以在一個運算式(expression)中,對一個基本型態的變數修改其值,
而且還在同一個式子的其他地方為了其他目的而存取該變數的值。(其他目的,
是指不是為了計算這個變數的新值的目的)。否則,將導致未定義的行為。
=========================================================================
便在論及這件事情。
網路上的一篇文章,推薦給大家閱讀:)
http://www.ddj.com/cpp/184401892
節錄:
i = i++, was trying to modify the same int twice without a sequence point in
between. The parable I just wrote is trying to increment and read the value
of the same int without a sequence point in between. This cannot be done, not
portably at least. Compilers are granted great leeway to reorder or even
parallelize expression evaluations, especially for fundamental types like
ints."
in Expressions 5:4: 'Between the previous and next sequence point a scalar
object shall have its stored value modified at most once by the evaluation of
an expression. Furthermore, the prior value shall be accessed only to
determine the value to be stored.'
But fortunately, there's a simple way to avoid it: Never write code that does
things it shouldn't do between sequence points, like try to write into the
same int, or other built-in scalar value, more than once in the same
expression."
--
最後再偷推一下C++ Primer 讚!! XD~
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.125.68.140
※ 編輯: aoc90058 來自: 59.125.68.140 (02/03 23:44)
※ 編輯: aoc90058 來自: 59.125.68.140 (02/03 23:47)
※ 編輯: aoc90058 來自: 59.125.68.140 (02/03 23:48)
※ 編輯: aoc90058 來自: 59.125.68.140 (02/03 23:53)
※ 編輯: aoc90058 來自: 59.125.68.140 (02/04 00:00)