C stdbool.h - sonkoni/Koni-Wiki GitHub Wiki
๋ถ๋ฆฐ ํ์ ๋งคํฌ๋ก
-
bool ~
_Bool๋ํ ๋งคํฌ๋ก - true ~ ์ฐธ 1
- false ~ ๊ฑฐ์ง 0
-
__bool_true_false_are_defined~ ๋ถ๋ฆฐ์ด ์ ์๋์ด ์๋์ง ์ฌ๋ถ
๋ถ๋ฆฐ์ ์๋ C ์ ์๋ค๊ฐ C99 ์ ์ถ๊ฐ๋๋ฉด์ _Bool ๋ก ์ง์ ๋์๊ณ , ์ด๋ฅผ bool ๋ก ํธํ๊ฒ ์ฐ๊ธฐ ์ํ ๋งคํฌ๋ก์ด๋ค.
#ifndef __STDBOOL_H
#define __STDBOOL_H
/* Don't define bool, true, and false in C++, except as a GNU extension. */
#ifndef __cplusplus
#define bool _Bool
#define true 1
#define false 0
#elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
/* Define _Bool as a GNU extension. */
#define _Bool bool
#if __cplusplus < 201103L
/* For C++98, define bool, false, true as a GNU extension. */
#define bool bool
#define false false
#define true true
#endif
#endif
#define __bool_true_false_are_defined 1
#endif /* __STDBOOL_H */#include <stdio.h>
#include <stdbool.h>
int main(int argc, char *argv[]) {
printf("__bool_true_false_are_defined : %d\n", __bool_true_false_are_defined);
printf("true : %d\n", true);
printf("false : %d\n", false);
printf("bool size : %zu Byte\n", sizeof(bool));
return 0;
}
// __bool_true_false_are_defined : 1
// true : 1
// false : 0
// bool size : 1 Byte