Boolean Type in MikroC

General discussion on mikroC for dsPIC30/33 and PIC24.
Post Reply
Author
Message
Traccker
Posts: 4
Joined: 02 Jun 2009 00:19

Boolean Type in MikroC

#1 Post by Traccker » 03 Jun 2009 18:28

Hello all

Is it possible to use Boolean types in MikroC?
I'd like to use easy values like true and false.
Not more than 1 bit needed.

I mean a code like:

Code: Select all

bool test
test = true;

void main(void)
{
  while(true)
  {
    
    if(test==true)
    {
    functionA();
    test=false;
    }
    else
    {
    functionB();
    test=true;
    }
  }
}
Why do this not work in MikroC? How Can I do the same code, using a bit only?

Kind regards
Traccker McFlak

User avatar
mileta.miletic
mikroElektronika team
Posts: 493
Joined: 05 Jun 2009 14:46
Location: Belgrade, Serbia
Contact:

#2 Post by mileta.miletic » 09 Jun 2009 15:20

We are working on one bit type support for mikroC for dsPIC30/33 and PIC24.
Regards,
Mileta

womai
Posts: 239
Joined: 16 Apr 2008 07:45

#3 Post by womai » 10 Jun 2009 23:22

You could use MikroC's bit access to check only a single bit in a byte, so you can pack up to 8 boolean values into a single char variable.

char flags;

flags.f0 = 1; // true
flags.f4 = 0; // false

if (flags.f0) { .... }
if (flags.f4) { .... }


More elegant and readable of course if you use #define:

#define TRUE 1
#define FALSE 0

#define bool_val_1 flags. f0
#define bool_val_2 flags. f4

char flags;

bool_val_1 = TRUE;
bool_val_2 = FALSE;

if (bool_val_1) { .... }
if (bool_val_2) { .... }

Wolfgang

Traccker
Posts: 4
Joined: 02 Jun 2009 00:19

#4 Post by Traccker » 22 Jun 2009 13:19

Thanks!!! This works well.

Post Reply

Return to “mikroC for dsPIC30/33 and PIC24 General”