Ç编译错误:"可变大小的物体可能无法初始化" [英] C compile error: "Variable-sized object may not be initialized"

查看:359
本文介绍了Ç编译错误:"可变大小的物体可能无法初始化"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我收到错误可变大小的物体可能无法初始化具有以下code?

  INT boardAux [长度] [长度] = {{0}};


解决方案

我假设你使用的是C99编译器(带有支持动态大小的数组)。在code的问题是,在当编译器看到你的变量声明的时候就不能知道有多少元素在数组中(我也是这里假设,从长度编译器错误不是编译时间常数)。

您必须手动初始化数组:

  INT boardAux [长度] [长度];
memset的(boardAux,0,长度*长度*的sizeof(INT));

Why do I receive the error "Variable-sized object may not be initialized" with the following code?

int boardAux[length][length] = {{0}};

解决方案

I am assuming that you are using a C99 compiler (with support for dynamically sized arrays). The problem in your code is that at the time when the compilers sees your variable declaration it cannot know how many elements there are in the array (I am also assuming here, from the compiler error that length is not a compile time constant).

You must manually initialize that array:

int boardAux[length][length];
memset( boardAux, 0, length*length*sizeof(int) );

这篇关于Ç编译错误:"可变大小的物体可能无法初始化"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆