2014-02-12 35 views
1

在函數聲明載體的情況下,我只是試圖定義一個在功能createlist命名numlist載體,但我得到的錯誤是:錯誤使用C

expected constant expression 
cannot allocate an array of constant size 0 
'numlist' : unknown size 
'numlist' undeclared identifier 

它只是這一行的功能

int langd=3; 
int numlist[langd]; 

回答

5

您正在使用c89編譯器,可變長度數組是c99功能。

要修復程序,使用一個常數:

#define LANGD 3 

int langd = LANGD; 
int numlist[LANGD]; 
+0

對不起,忘了說,我需要從參數數組的大小,功能及其在,如:INT函數(INT一個){ int numlist [a]; .........} – Tensora

+0

@Tensora在這種情況下,使用'malloc'函數:'int * numlist = malloc(a * sizeof * numlist);'。 – ouah

+0

似乎工作正常! – Tensora