前言
程式設計挑戰 計算機日期
第二章 這不是bug,而是語言特徵
*switch的乙個bug—break中斷了什麼
第三章 分析c語言宣告
程式設計挑戰 把c 語言的宣告翻譯成通俗的語言
#include #includeview code#include
#include
#define max_len 100
enum
type_token ;
typedef
struct
tokentoken;
token tmp_token;
typedef
struct
stackstack;
struct
stack token_stack;
void init(stack *sta)
int push(stack *sta,token s)
else
return0;
}token pop(stack *sta)
else
}int stack_empty(const
stack s)
token top_stack(
const
stack s)
else
return
s.array[s.top];
}enum
type_token classify_string();
void
gettoken()
ungetc(*p,stdin);//
把非滿足的字元放回緩衝區,下次再用
*p='\0'
; tmp_token.type=classify_string();
return
; }
if(*p=='*'
) tmp_token.
string[1]='\0'
; tmp_token.type=*p;
return;}
enum
type_token classify_string()
if(!strcmp(s,"
volatile
")) return
qualifier;
if(!strcmp(s,"
extern
")) 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
read_first_identifier()
printf(
"%s is
",tmp_token.string
); gettoken();
}void
deal_with_array()
gettoken();
//讀取『】』之後的token
printf("
of "
); }
}void
deal_with_function()
void
deal_with_pointer()
}void deal_with_declarator()
deal_with_pointer();
while(stack_empty(token_stack)==1
)
else
}}int
main()
《C專家程式設計》讀書筆記
第一章 const float 表示乙個指向float型別常量的指標 第二章 1.在c語言中const並非真正表示 常量 在陣列定義與case中不可以使用 2.case的一些問題 2 3 main 15 這段 列印出來的是 3.函式可見性 void sb any where 2 extern voi...
《C專家程式設計》讀書筆記9
第九章 再論陣列 宣告本身還可以進一步分成3種情況 外部宣告 external array 的宣告。陣列的定義 記住,定義是宣告的一種特殊情況,它分配記憶體空間,並可能提供乙個初始值 函式引數的宣告。所有作為函式引數的陣列名總是可以通過編譯器轉換為指標。作為函式定義的形式引數,char s和 cha...
《C專家程式設計》讀書筆記10
第十章 再論指標 char pea 4 6 的記憶體布局。單個元素的儲存和引用是以線性形式排列在記憶體中的。首先找到pea i 的位置,然後根據偏移量 j 取得字元。因此,pea i j 將被編譯器解析為 pea i j 可以通過宣告乙個一維指標陣列,其中每個指標指向乙個字串來取得類似二維字元陣列的...