반응형
C 언어는 bool 자료형이 없었다.
그래서
typedef enum {false, true} bool;
이렇게 정의해서 쓰거나
#define FALSE 0
#define TRUE 1
이렇게 정의 해서 썼다고 한다.
시간이 흘러 C++이 나왔고 C++에서는 bool 자료형과 true, false 값을 지원하였다.
그리고 결국 C 언어에서도 불 자료형의 필요성에 계속 제기되면서
C99표준부터는 stdbool.h 헤더파일이 추가되었고,
여기에서 bool 변수가 추가 되었다.
//
// stdbool.h
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// The C Standard Library <stdbool.h> header.
//
#ifndef _STDBOOL
#define _STDBOOL
#define __bool_true_false_are_defined 1
#ifndef __cplusplus
#define bool _Bool
#define false 0
#define true 1
#endif /* __cplusplus */
#endif /* _STDBOOL */
sizeof(bool) 로 값을 알아보니 bool 변수는 1byte 이다.
반응형
'C언어(2020년)' 카테고리의 다른 글
22. const (0) | 2020.11.04 |
---|---|
21. 구조체 (0) | 2020.11.03 |
19. 연산자 (0) | 2020.11.03 |
18. 연산자 우선순위 (0) | 2020.11.03 |
17. 포인터 (1) | 2020.11.03 |