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

后端 未结 8 1657
借酒劲吻你
借酒劲吻你 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:34

    Definitions are not executable code. They are just instructions to the compiler, letting it know the size and the type of the variable. In this sense, the definition is not bypassed by the goto statement.

    If you use a class with a constructor instead of an int, the call of the constructor would be bypassed by the goto, but the storage would be allocated anyway. The class instance would remain uninitialized, however, so using it before its definition/initialization line gets the control is an error.

提交回复
热议问题