c語言的宣告有時候是及其複雜的,不如char * (* c[10]) (int **p); 這樣宣告即使讓c語言老手看到也會不寒而慄,有沒有想過讓程式幫我們把這麼難懂的宣告翻譯成比較通俗易懂的語言呢?完全可以!
先來個簡單的:int i;
再來個指標: int * p
看看複雜一點的: char * const * (* next) ();
最後看看這個
char * (* c[10]) (int **p);是什麼東西:
是不是比你乙個乙個分析要簡單的多了
貼上**吧 //
#include #include #include #include #define maxtokens 100
#define maxtokenlen 64
enum type_tag ;
struct token ;
int top = -1;
struct token stack[maxtokens];
struct token this;
#define pop stack[top--]
#define push(s) (stack[++top] = s)
enum type_tag classify_string(void)
/* 推斷標示符的型別 */
if(!strcmp(s, "volatile"))
return qualifier;
if(!strcmp(s, "void"))
return type;
if(!strcmp(s, "char"))
return type;
if(!strcmp(s, "signed"))
return type;
if(!strcmp(s, "unsigned"))
return type;
if(!strcmp(s, "short"))
return type;
if(!strcmp(s, "int"))
return type;
if(!strcmp(s, "long"))
return type;
if(!strcmp(s, "float"))
return type;
if(!strcmp(s, "double"))
return type;
if(!strcmp(s, "struct"))
return type;
if(!strcmp(s, "union"))
return type;
if(!strcmp(s, "enum"))
return type;
return identifier;
}void gettoken(void)
if (*p == '*')
this.string[1] = '\0';
this.type = *p;
return;
}/* 理解所以分析過程的**段 */
read_to_first_identifer()
printf("%s is ", this.string);
gettoken();
}deal_with_arrays()
gettoken();
printf("of "); }}
deal_with_function_args()
gettoken();
printf("function returning ");
}deal_with_pointers()
}deal_with_declarator()
deal_with_pointers();
while (top >= 0)
else }}
main()
C語言宣告解析
首先,來看乙個簡單的例子 int a1 a1是乙個int int a2 a2是乙個陣列,它的每乙個元素是乙個int int a3 a3是乙個陣列,它的每乙個元素是乙個int 即,它的每乙個元素是乙個指向int的指標 int a4 a4是乙個指標,它指向乙個int陣列 可能上面的3 4兩行比較容易混淆...
解析C語言宣告
在學習c語言的過程中,會先遇到陣列指標,指標陣列此類的概念。這些概念實在是晦澀難懂,在進一步學習之後,你會發現更加恐怖的還有各種各樣的宣告,比如 char const next 那麼這些宣告到底是什麼意思呢?序號說明 a宣告從他的名字開始讀取,然後按照優先順序順序依次讀取 b優先順序從高到低依次是 ...
深入解析C語言宣告
如果說c語言宣告很簡單的人不是牛人就是還沒入門。本文來講解c語言的宣告的一些基本內容,很多內容參考 c專家程式設計 首先由乙個最簡單的問題引入,你知道 int p 5 和 int p 5 的區別在 嗎?把後面的答案遮到,想想。也許你知道反正乙個是含有五個指向整型的指標元素的指標陣列,另乙個是指向乙個...