Page 1 of 1

declaring a "bit" to use as a flag in flowcode 5

Posted: Sun Feb 12, 2017 10:36 pm
by davet
Hi all!
I am trying to set up some bits as flags (in "C" ), such as:

In the supplementary code window.

bit myflag;

but boostc does not seem to recognise "bit" i.e. it does not highlight in blue.
it states in the boostc manual for example "bit b; //variable will be placed by linker at arbitrary position"

Any help much appreciated!

Dave

Re: declaring a "bit" to use as a flag in flowcode 5

Posted: Mon Feb 13, 2017 11:29 am
by Benj
Hi Dave,

You can try the following.

Code: Select all

bool myflag;
If I were you I would use say a byte variable and use this to pack 8 bool values. Otherwise your bool values will each likely consume a whole byte anyway on their own. They certainly do for GCC based compilers which surprised me.

Setting a bit in the byte.

Code: Select all

flags = flags | (1 << bitnum)
Clearing a bit in the byte.

Code: Select all

flags = flags & ~(1 << bitnum)
Testing a bit in the byte, as 0 or 1.

Code: Select all

test = (flags & (1 << bitnum)) >> bitnum
bitnum = 0-7

This will also simulate correctly in v5 as you can do it all with calculation icons instead of C icons.

Re: declaring a "bit" to use as a flag in flowcode 5

Posted: Mon Feb 13, 2017 12:10 pm
by davet
Thanks for the quick reply Benj!
Thanks for that solution, makes sense!
Just being pedantic here, why is "bit" not recognised by the complier?
Cheers

Dave

Re: declaring a "bit" to use as a flag in flowcode 5

Posted: Mon Feb 13, 2017 1:09 pm
by Benj
Hi Dave,
Just being pedantic here, why is "bit" not recognised by the complier?
That's a question for the guys at sourceboost :D probably just goes back to the days pre-GCC where things in C were a bit less well defined.

Re: declaring a "bit" to use as a flag in flowcode 5

Posted: Mon Feb 13, 2017 6:36 pm
by davet
Thanks Benj!