Implementing Tribool with int8_t For digital electronic circuit simulation, i wanted to implement Three states. i.e High, Low and Undefined in C++.

I saw Boost::tribool, and they implement it using enum

Now for conserving some memory i have implemented it using 1 Byte Int

#ifdef _WINDOWS
typedef __int8 State;
#elif
typedef int8_t State;
#endif

const State kLow = 0;
const State kHigh = 1;
const State kUndefined = 2;



Do you see any potential problem with it?
And why would one waste 4 bytes instead of a single byte for 3 values only
Do you have a still better way?
I would definitely recommend using enumerations. As this is December 2011, I would imagine your compiler supports an explicit underlying type on enumerations (GCC supported this since 4.4 and Visual C++ now supports it in 11.0). As a side note, &lt;cstdint&gt; is supported by visual c++ now (as of 10.0).

As an addenum to traditional c-style enumerations:

enum state : std::int8_t {
    S_UNKNWON,
    S_HIGH,
    S_LOW
};


Or adding scope to the enumeration's memebers (avoid polluting global scope):

enum class state : std::int8_t {
    unknown,
    high,
    low
};

state status = state::unknown;


Of course, after looking at boost::tribool, I would recommend that over anything -- unless you really need to ensure that state is exactly 1 byte.