Why is it OK to jump into the scope of an object of scalar type w/o an initializer?

后端 未结 2 1723
甜味超标
甜味超标 2021-01-05 11:30

When I\'m reading the C++ standard, it seems that the following code is perfectly fine according to the standard.

int main() {
   goto lol;
   {
      int x;         


        
2条回答
  •  有刺的猬
    2021-01-05 11:47

    Isn't it still dangerous to jump over its definition and use uninitialized x?

    But x would be uninitialized anyway, because it was declared without an initializer! So the goto might be skipping over assignment statements that set (sort-of-initialize) x, but it's not surprising that goto can skip over assignment statements; and the declaration itself doesn't actually do anything unless there's an initializer.

提交回复
热议问题