C reserved keywords
存儲類型說明符 storage-class specifier
keywords | meaning |
---|---|
auto | automatic duration storage-class specifier with no linkage |
extern | static duration storage-class specifier with either internal or more usually external linkage |
register | automatic duration storage-class specifier with no linkage. Hints that the variable will be used heavily |
static | static duration storage-class specifier with internal linkage at file scope and no linkage at block scope |
static array indices in function parameter declarations (since C99) |
跳轉, 條件, 循環語句聲明符 statement declarator
keywords | meaning |
---|---|
break | |
continue | |
goto | |
return | |
if | if statement |
else | if statement: alternative branch |
switch | switch statement |
case | switch statement: case labels |
default | switch statement: efault case label |
type-generic expression: as the declaration of the default generic association(since C11) | |
do | do-while loop |
for | for loop |
while | while loop |
do-while loop: terminating condition of the loop |
類型聲明符 type declarator
keywords | meaning |
---|---|
char | |
int | |
double | |
enum | enumeration type |
float | |
inline | inline function specifier |
struct | compound type |
union | |
typedef | |
void | incomplete type |
in a function with no parameter or no return value |
類型修飾符 type modifier
keywords | meaning |
---|---|
long | long type modifier |
short | short type modifier |
signed | signed type modifier |
unsigned | unsigned type modifier |
類型限定符 type qualifier
keywords | meaning |
---|---|
const | const type qualifier |
restrict | restrict type qualifier |
volatile | volatile type qualifier |
操作符 operator
keywords | meaning |
---|---|
sizeof | sizeof operator |
inline
- 使用 inline 關鍵字聲明內聯函數 Inline function, 內聯函數在某些情況下類似於宏, 直接將代碼內嵌到調用它的父函數中
- 編譯時需要指定優化等級爲 -O3 才能被內嵌, 也可以指定內嵌函數屬性 #pragma always_inline 強制內嵌
- 使用 ISO C 標準的時候,可以使用 __inline__ 關鍵字代替 inline 關鍵字
有幾種情況將不內嵌,而作爲普通函數調用:
- 可變參數的函數
- 調用 alloca 類庫的函數
- 有可變尺寸數組聲明的函數
- 非本地 goto 的函數
- 嵌套調用的函數
const
- 使用 const 限定符修飾形參可以防止函數修改傳入的參數
- 使用 const 限定符修飾指針和引用