Greetings.
In article <bm**********@p hys-news1.kolumbus. fi>, Ian Tuomi wrote:
How can I define a boolean value in c? (an value that can only be either
1 or 0) I feel bad for the memory loss when declaring ints for variables
that do not need that much memory.
According to the latest C standard, which your compiler may, may not, or may
only partially support:
#include <stdbool.h>
_Bool foo;
Note that using the new boolean type doesn't guarantee that the compiler is
actually going to set aside just one bit of memory for the variable. In
fact, it probably won't. In practice, the low-level machine code
operations required to test individual bits are typically slower than those
used to compare whole words anyway. So even if you could squeeze your
boolean variables down to a single bit in size, you'd be trading off
execution speed.
If you're worried about memory and speed optimizations, concentrate on
choosing efficient algorithms. Microoptimizati ons such as you propose are
generally a waste of the programmer's time for all but the most constrained
execution environments.
Regards,
Tristan
--
_
_V.-o Tristan Miller [en,(fr,de,ia)] >< Space is limited
/ |`-' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= <> In a haiku, so it's hard
(7_\\
http://www.nothingisreal.com/ >< To finish what you