What are the candidate types of Boolean values in C? Why is it not a standard type?

Source: Internet
Author: User
What are the candidate types of Boolean values in C? Why is it not a standard type? Should I use # define or enum to define true and false values? C language does not provide a standard boolean type, because selecting such a type involves the best ProgramSpace/time compromise decided by members. (Using int may be faster, while using char may save more data space. However, if the int type needs to be converted repeatedly, the small type may also generate larger or slower Code.)

You can use the # define or enumeration constant to define true/false. Use any of the following forms

# Define true 1 # define Yes 1 # define false 0 # define no 0 Enum bool {false, true}; Enum bool {No, yes };

Or directly use 1 and 0, as long as they are consistent in the same program or project. If your debugger displays the name of an enumerated constant while viewing the variable, it may be better to use enumeration.

Some people prefer this definition.

# Define true (1 = 1) # define false (! True)

Or define a ''secondary" macro like this.

# Define istrue (E) (e )! = 0)

But this is not helpful.

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.