Statement goto can not cross variable definition?

前端 未结 2 1282
失恋的感觉
失恋的感觉 2020-12-24 06:15

Suppose these code compiled in g++:

#include 

int main() {
    int a =0;

    goto exit;

    int *b = NULL;

exit:
    return          


        
2条回答
  •  盖世英雄少女心
    2020-12-24 06:54

    There is an easy work-around for those primitive types like int:

     // ---  original form, subject to cross initialization error.  ---
     // int foo = 0;
    
     // ---  work-around form: no more cross initialization error.  ---
     int foo;  foo = 0;
    

提交回复
热议问题