2008년 5월 25일 일요일

bool과 BOOL의 차이

 






1.요약
bool과 BOOL의 차이에 대해 알아본다.


2.본문
- bool : 기본 C++의 데이터 타입, 1바이트의 크기
true, false값만 갖는다. true와 false 역시 C++의 기본 키워드
- BOOL : MFC에서 정의되어 있는 데이터 타입, 1바이트가 아니라 4바이트의 크기
TRUE, FALSE 값을 갖고 true와 false 역시 가능
TRUE와 FALSE역시 MFC에서 정의되어 있는 키워드

3.예제

CString msg; 

msg.Format("bool's sizeof : %d, BOOL's sizeof : %d",sizeof(bool), sizeof(BOOL)); 

AfxMessageBox(msg); 

4.결과 bool's sizoef : 1, BOOL's sizeof : 4


사용자 삽입 이미지

5.참고

MSDN 에서 찾아보니 아래와 같은 글이 있었습니다.

Microsoft Specific

In Visual C++4.2, the Standard C++ header files contained a typedef that equated bool with int. In Visual C++ 5.0 and later, bool is implemented as a built-in type with a size of 1 byte. That means that for Visual C++ 4.2, a call of sizeof(bool) yields 4, while in Visual C++ 5.0 and later, the same call yields 1. This can cause memory corruption problems if you have defined structure members of type bool in Visual C++ 4.2 and are mixing object files (OBJ) and/or DLLs built with the 4.2 and 5.0 or later compilers.

즉, 4.2에서는 int 와 같은 형으로 선언이 되어 있었는데, 후에 built-in type 으로 바뀌면서 1 byte로 바뀌었다는 군요..



- 2001.08.13 Smile Seo -

출처 : http://www.debuglab.com/knowledge/bool.html

댓글 1개:

  1. Hey there! Do you know if they make any plugins to
    help with SEO? I'm trying to get my blog to rank for some targeted keywords but I'm not seeing very good success.

    If you know of any please share. Thank you!

    Look at my web page: clash of clans hack (zoetinstijl.nl)

    답글삭제