Whither bool?

General discussion on mikroC PRO for AVR.
Post Reply
Author
Message
craigmeister
Posts: 11
Joined: 28 Mar 2012 20:07

Whither bool?

#1 Post by craigmeister » 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.

borris
Posts: 219
Joined: 22 Aug 2011 07:13

Re: Whither bool?

#2 Post by borris » 11 Sep 2012 22:30

I'd sure like to use it. Does it do anything other than being a reserved keyword?

User avatar
dejan.odabasic
mikroElektronika team
Posts: 2649
Joined: 30 Apr 2012 14:20

Re: Whither bool?

#3 Post by dejan.odabasic » 12 Sep 2012 08:23

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.
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.
Best regards.

borris
Posts: 219
Joined: 22 Aug 2011 07:13

Re: Whither bool?

#4 Post by borris » 13 Sep 2012 06:15

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:

Code: Select all

typedef enum ebool { FALSE, TRUE } boolean
Works most of the time, but not a ideal solution.

User avatar
dejan.odabasic
mikroElektronika team
Posts: 2649
Joined: 30 Apr 2012 14:20

Re: Whither bool?

#5 Post by dejan.odabasic » 13 Sep 2012 07:59

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.

public2010
Posts: 94
Joined: 05 May 2009 18:31
Location: Somewhere in Europe

Re: Whither bool?

#6 Post by public2010 » 30 Nov 2021 18:21

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.
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.
Probably a bug in the mikroC for AVR compiler !!!

Post Reply

Return to “mikroC PRO for AVR General”