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

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
davet
Posts: 27
Joined: Mon Jun 11, 2012 11:08 am
Been thanked: 1 time

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

Post 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

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

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

Post 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.

davet
Posts: 27
Joined: Mon Jun 11, 2012 11:08 am
Been thanked: 1 time

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

Post 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

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

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

Post 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.

davet
Posts: 27
Joined: Mon Jun 11, 2012 11:08 am
Been thanked: 1 time

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

Post by davet »

Thanks Benj!

Post Reply