Bool under VC

Source: Internet
Author: User

I didn't want to name the note title "bool under VC", because I encountered another problem that has not been resolved yet, however, I learned some knowledge about bool and bool through this question. Here we will talk about our understanding: bool is a keyword in C ++, And the bool type is an integer, but its size is not fixed. In VC, the implementation of its size was also different. Before VC ++ 4.2, its size was 4 bytes, and after VC ++ 5.0, the size is 1 byte. Therefore, if a project is mixed with mfc4.2 and mfc5.0 OBJ, the DLL file may have memory conflicts and other problems. Therefore, there is a macro definition about bool in MFC, which is defined as the int type. One can improve its compatibility, and the other can use bool flexibly, because bool has only two values while bool is an integer, it is said that multiple interface statuses can be returned (I don't know much about this, but I think so now .).

Appendix: There is no bool definition in C's original standard. The non-zero value in the previous logical expression represents logical truth, and the zero value represents logical false. The New Keyword _ bool is introduced in ANSI 99. This type of variable has only two values: 1, 0, and 1. It is true, and 0 is false. Later, c99 provided a stdbool. h header file, so we can use bool to replace _ bool. True to represent 1, and false to represent 0.ProgramThis header file can be written to be compatible with C ++.Code. In C ++, bool, true, and false are keywords.

The following briefly describes my problem: I plan to complete a small program under VC ++ 6.0, that is, count the number of "EI" in the input string, but there are two problems: first, I used bool in VC for a long time and it was not successful. the second is for # include <windows. h> This header file can be compiled only when this header file is added. Passers-by may wish to make a speech and remind me. Thank you!

Source code:

# Include <stdio. h>
# Include <windows. h>

# define stop' # '
int main (void)
{< br> int counter = 0;
char ch;
bool flag = false;
while (CH = getchar ())! = Stop)
{< br>
If (CH = 'E')
{< br> flag = true;
continue;
}< br> If (CH = 'I' & flag)
counter ++;
flag = false;

}< br> printf ("/'ei/'appear % d times/N", counter);
}

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.