Whither bool?
-
- Posts: 11
- Joined: 28 Mar 2012 20:07
Whither bool?
"bool" is listed as a keyword, but I get an error when I use it. Compiler does not recognize "boolean" as a declaration either.
Re: Whither bool?
I'd sure like to use it. Does it do anything other than being a reserved keyword?
- dejan.odabasic
- mikroElektronika team
- Posts: 2649
- Joined: 30 Apr 2012 14:20
Re: Whither bool?
Hello,
Since C99 bool is reserved keyword in C programming language, but it's not implemented as a variable type in mikroC PRO.
As you many know Boolean variable type requires additional library.
#include <stdbool.h>
I suggest that you use bit variable instead.
The mikroC PRO for ... compiler provides a bit data type that may be used for variable declarations. It can not be used for argument lists, and function-return values.
Since C99 bool is reserved keyword in C programming language, but it's not implemented as a variable type in mikroC PRO.
As you many know Boolean variable type requires additional library.
#include <stdbool.h>
I suggest that you use bit variable instead.
The mikroC PRO for ... compiler provides a bit data type that may be used for variable declarations. It can not be used for argument lists, and function-return values.
Best regards.Note :
Bit variables can not be initialized.
Bit variables can not be members of structures and unions.
Bit variables do not have addresses, therefore unary operator & (address of) is not applicable to these variables.
Re: Whither bool?
bit type is great and I use it alot, however, I need to use them as members of union and structs. I've been using this:
Works most of the time, but not a ideal solution.
Code: Select all
typedef enum ebool { FALSE, TRUE } boolean
- dejan.odabasic
- mikroElektronika team
- Posts: 2649
- Joined: 30 Apr 2012 14:20
Re: Whither bool?
Hello,
using the (unsigned) char variable (which holds only 0 or 1) as members of union and structures usually is not too "expensive".
Since byte is the smallest addressable unit of memory. Multiple bits placed into a byte requires additional bit-shift operations which makes the bool an inefficient variable type to be implemented.
Best regards.
using the (unsigned) char variable (which holds only 0 or 1) as members of union and structures usually is not too "expensive".
Since byte is the smallest addressable unit of memory. Multiple bits placed into a byte requires additional bit-shift operations which makes the bool an inefficient variable type to be implemented.
Best regards.
-
- Posts: 94
- Joined: 05 May 2009 18:31
- Location: Somewhere in Europe
Re: Whither bool?
Hi, I know it's been about 9 years since your intervention, but now I've found that the bool function only works in a custom "void", it doesn't work in void main.craigmeister wrote: ↑07 Apr 2012 00:11"bool" is listed as a keyword, but I get an error when I use it. Compiler does not recognize "boolean" as a declaration either.
Probably a bug in the mikroC for AVR compiler !!!