Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

#include <stdbool.h>

Name: Anonymous 2011-10-14 14:26

The header stdbool.h in the C Standard Library for the C
programming language contains four macros for a Boolean data
type. This header was introduced in C99, which was adopted as
an ANSI standard in May 2000. 11 years ago.


#ifndef _STDBOOL_H
#define _STDBOOL_H

#define bool _Bool
#define true 1
#define false 0
#define __bool_true_false_are_defined 1

#endif


Spread the word!

Name: Anonymous 2011-10-14 14:49

>>2
Built-in compiler defined type. Identifier names with an underscore as a prefix are reserved as for future language expansions and compiler and library implementors. However, bool was not a reserved identifier in C89.

stdbool.h was created so that C99, and future versions of C such as C1x would remain backwards compatible with C89 code. For example, many C developers would create their own bool typedefs. On new projects, you can optional include stdbool.h. On existing projects, things work as per normal.

>>3
C99 is mostly full supported, except with Microsoft's shitty compiler toolchain.

>>4
Better semantics and type-safety. Plus bool can be implemented as a single byte (with ICC, GCC and Clang you choose this with a compiler flag), but int has to be at least 16-bits according to the language standard, as the minimum allowed values for INT_MAX and UINT_MAX in limits.h are 32767 and 65535 respectively. In practice with modern compilers and on most current platforms, int is a 32-bit integer type--but you already knew that.

Name: Anonymous 2011-10-14 15:02

>>5

Out of curiosity, I always wondered why people didn't use char instead of int for representing booleans in pre-C99 code.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List