我发现这拒绝编译:
int test_alloc_stack(int size){
if(0) goto error; // same issue whatever conditional is used
int apply[size];
give_values(apply,size);
return 1;
error:
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:"跳转到具有可变修改类型的标识符范围".使用"goto"消除行并跳转到错误可以解决问题.
如果我使用动态分配申请,那么问题也会消失.编译好:
int test_alloc_heap(int size){
if(0) goto error;
int * apply = calloc(sizeof(int),size);
give_values(apply,size);
free(apply);
return 1;
error : return 0;
}
Run Code Online (Sandbox Code Playgroud)
到底是怎么回事 ?