C 에서 Boolean 타입 사용
앎/c_cpp 2014. 2. 18. 18:07 |C99 이전의 C에서는 Boolean 타입이 존재하지 않았다.
따라서 bool 타입을 따로 정의해서 사용했다.
typedef int bool #define false 0 #define true 1 bool b = false;
C99 에 들어와서는 Boolean 타입을 지원하게 되었다.
#ifndef __cplusplus #define bool _Bool #define true 1 #define false 0 #else /* __cplusplus */ /* Supporting <stdbool.h> in C++ is a GCC extension. */ #define _Bool bool #define bool bool #define false false #define true true #endif /* __cplusplus */ /* Signal that all the definitions are present. */ #define __bool_true_false_are_defined 1
위 내용처럼 C나 C++ 에서 모두 bool 타입으로 사용하면 된다.
#include <stdbool.h> bool b = true;
'앎 > c_cpp' 카테고리의 다른 글
C 연산자 우선순위 (0) | 2014.02.19 |
---|