This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

STM32 boolean types?

Hi, i'm using Keil Evaluation Boards to program my STM32F4Discovery. I was wondering, why can't I use boolean or bit type data? Or it's because i'm using the Evaluation version? I want to use "true" or "false" value, maybe i can use another type data besides that two buddies? I'll be happy and glad if anybody can help me with this one. Sorry for my bad english...

Parents
  • why
    Well, bool is generally used for storing & checking true/false or 1/0. Logically, for storing only 2 values, 1 binary bit is enough.

    Controllers have low on-chip ram memory & hence external memory is interfaced.
    If an engineer (having only on-chip ram) misuses ram memory (and doesn't know how to reduce ram usage or use it efficiently), then he may either have to modify hardware or modify software after getting stuck up or compromise on the features of the embedded device he is writing the software for.
    now-a-days the controllers (generally) dont have bit/byte addressible area as in x51.

Reply
  • why
    Well, bool is generally used for storing & checking true/false or 1/0. Logically, for storing only 2 values, 1 binary bit is enough.

    Controllers have low on-chip ram memory & hence external memory is interfaced.
    If an engineer (having only on-chip ram) misuses ram memory (and doesn't know how to reduce ram usage or use it efficiently), then he may either have to modify hardware or modify software after getting stuck up or compromise on the features of the embedded device he is writing the software for.
    now-a-days the controllers (generally) dont have bit/byte addressible area as in x51.

Children
  • Well, bool is generally used for storing & checking true/false or 1/0. Logically, for storing only 2 values, 1 binary bit is enough.

    An admirable reason. On more than one occasion I have commented a bool in C51 as "true or false or maybe"

    It would have been better for you to say at the first that you'd prefer bool and bit to be precisely one bit rather than wanting them both to be the same (unspecified) size. That would have removed any doubt in what you meant.

  • Lost of embedded programs have quite a limited number of global boolean variables, so the amount of memory consumed by using a byte instead of a bit is often very marginal.

    At the same time, lots of embedded programs have quite limited code space, in which case the code size becomes just as critical as RAM space might be.

    Often, programs wastes too much RAM by using global variables for something that could have been local variables.

    And for lots of processors, a char or maybe even a full int variable can be much quicker to work with than a bit variable because of better matching to the processor instruction set. So boolean variables accessed by interrupts can give a big difference in interrupt latency if stored as a single bit or as a byte - besides the fact that if memory controller or instruction set doesn't have single-bit support then a single bit stored in a word can't be atomically updated resulting in lots of potential timing issues between main loop and interrupt handlers or between different threads.