When compiling C language, you may encounter the following error message: 'true' undeclared (first use in this function) or 'false' undeclared (first use in this function): bool, true, false is all undeclared, and the reason is very simple, because the real C does not have these keywords, C and the early C ++ do not have the keyword bool, you can use bool, but bool is not a built-in type, both are defined by typedef or macro, and are usually defined as int type. Later, the built-in type bool appeared in C ++. The values can only be true (1) and false (0 ). Solution: 1. Change file name. C to file name. cpp, and use C ++ to compile the file. 2. Define a macro by yourself:
Typedef Enum _ bool {false = 0, true = 1,} bool;
C90 does not have bool, So Dev-C ++ that supports C90 certainly does not. If you want to use bool in C90, you can use macros to define it.
C99 supports bool. You can use a compiler that supports c99, such as GCC.
This article is reproduced from ghost.