C stdbool.h - sonkoni/Koni-Wiki GitHub Wiki

๋ถˆ๋ฆฐ ํƒ€์ž… ๋งคํฌ๋กœ

๋ถˆ๋ฆฐ์€ ์›๋ž˜ 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
โš ๏ธ **GitHub.com Fallback** โš ๏ธ