Wednesday, 15 June 2011

c - Boolean - Optimized bool -



c - Boolean - Optimized bool -

traditionally, c did not have boolean defined until c99. thus, searching headers files know optimized way of creating boolean found are:

windows.h [microsoft c++] --------- typedef int bool; //false #ifndef false #define false 0 #endif //true #ifndef true #define true 1 #endif

defined in tipo booleano c

#if (__borlandc__ <= 0x460) || !defined(__cplusplus) typedef enum { false, true } bool; #endif

provided c-faq.com section 9

typedef enum {false, true} bool;

in objc.h bool defined as:

typedef signed char bool; // bool explicitly signed @encode(bool) == "c" rather "c" // if -funsigned-char used. #define objc_bool_defined #define yes (bool)1 #define no (bool)0

in reply question on stackoverflow.com

typedef enum { false = 0, true = 1 } bool; #define bool bool #define true true #define false false

which 1 optimized way?

if utilize c89, go next definitions:

#define true 1 #define false 0 typedef unsigned char bool;

for memory reasons, _bool 1-byte wide type. , in c99 _bool unsigned type.

i don't definitions of bool enum enum implementation-defined types while enum constant int.

now if want favor speed on memory, should consider using type matches word size of processor.

c gcc cross-platform boolean vc6

No comments:

Post a Comment