본문 바로가기
Study/C++

warning C4800 처리를 해보자

by 뿡뿡대마왕 2021. 1. 6.
반응형

 

warning 제거 작업을 하던중


warning C4800: 'BOOL' : 'true' 또는 'false'로 bool 값을 강제하고 있습니다

warning C4800 - 'int' forcing value to bool 'true' or 'false' with switch statement


예를 들어 이런 소스들이 존재한다고 할때



ex)

int i = 0;

bool bVal = i;        ///< warning 4800발생

BOOL bT = FALSE;

bool bZZ = bT;     ///< warning 4800발생


뭐 흔히들 저런 Warning 처리를 아래와 같이 해결하려 할것이다.


int i = 0;

bool bVal = static_cast<bool>i;        ///< warning 4800발생

BOOL bT = FALSE;

bool bZZ = static_cast<bool>(bT);     ///< warning 4800발생



위와같이 해도 마찬가지로 warning은 계속 발생한다.

C4800 으로 구글검색 GoGo!~ 그리고 MSDN에 내용이 검색되어 해당 내용을 보니 아래와 같다.


'type' : forcing value to bool 'true' or 'false' (performance warning)

This warning is generated when a value that is not bool is assigned or coerced into type bool. Typically, this message is caused by assigning int variables to bool variables where the int variable contains only values true and false, and could be redeclared as type bool. If you cannot rewrite the expression to use type bool, then you can add "!=0" to the expression, which gives the expression type bool. Casting the expression to type bool will not disable the warning, which is by design.

The following sample generates C4800:


ㅎㅎㅎ 이런..난 영어가 싫단 말이닷!

번역 고고고!!

이 경고는 bool이 아닌 값을 할당하거나 bool 형식으로 강제 변환할 때 발생합니다. 일반적으로 이 메시지는 true와 false 값만 있는 int 변수를 bool변수에 할당할 때 발생하며 이 경우 int 변수를 bool 형식으로 다시 선언할 수 있습니다. bool 형식을 사용하여 식을 다시 작성할 수 없으면 "!=0"를 식에 추가하여 bool 형식을 제공합니다. 식을 bool 형식으로 캐스팅해도 경고가 발생하도록 설계되었습니다.


!=0 을 가지고 처리하라고 해서 아래 처럼 하니 Clear ~~



int i = 0;

bool bVal = (i != 0);  

BOOL bT = FALSE;

bool bZZ = (bT != 0);



정보는 공유되어야 한다 쭈욱!@




반응형

댓글