C99 _Bool

C99定義了關鍵字 _Bool, 又另外新增了stdbool.h

#define bool _Bool
#define true 1
#define false 0
為什麼用_Bool這樣看起來有點奇怪的命名而不直接定義bool?
最主要的原因是因為在c89 bool並非保留字,
因此在擴展規範時只能從reserved identifier下手了
在c89的規範 7.1.3第一項提到
All identifiers that begin with an underscore and either an uppercase letter or
another underscore are always reserved for any use.

This entry was posted in C Language. Bookmark the permalink.

Leave a Reply