Bool variable in C Language

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.