How can a variable be used when its definition is bypassed?

后端 未结 8 1665
借酒劲吻你
借酒劲吻你 2020-12-09 02:11

In my mind, always, definition means storage allocation.

In the following code, int i allocates a 4-byte (typically) storage on program stack and bind

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-09 02:35

    To make it short, variable declaration is lexical, i.e. pertaining to the lexical {}-enclosed blocks. The binding is valid from the line it is declared to the end of the block. It is unaffected by flow control (goto).

    Variable assignment of locol (stack) variables, on the other hand, is a runtime operation performed when the control flow gets there. So goto has an influence on that.

    Things get a bit more tricky when object construction becomes involved, but that's not your case here.

提交回复
热议问题