2015-10-15 21 views
-1
static const unsigned int x[] = { 1, 2, 3, 5 }; 
static const int q = sizeof(x) **/** sizeof(x[0]); 

size_t fun(int n, int m) 
{ 
    unsigned int p[q]; 
} 

如何解決此錯誤?這是一個C代碼。錯誤C2057:vs2008中的預期常量表達式

+1

'無符號整型P [的sizeof(X)/的sizeof(X [0])];'或'的#define Q(的sizeof(X)/的sizeof(X [0]))'代替'靜態const int q = sizeof(x)/ sizeof(x [0]);' – BLUEPIXY

回答

0

這是什麼**/** sizeof(x[0]);,這不是如何發表評論,也不要忘記在表達式的末尾加上分號。

static const unsigned int x[] = { 1, 2, 3, 5 }; 

static const int q = sizeof(x)/sizeof(x[0]); /* sizeof(x[0]); */ 

size_t fun(int n, int m) 
{ 
    unsigned int p[q]; 
} 

int main() 
{ 
}