Suppose I did this:
Assuming the sytax is correct (not sure about thatCode:struct Stuff { var : 1 var2 : 4 unused : 3 }; Stuff stuff;), could I say "stuff.var = true;"? And then, could I manipulate var2 as an int?
This is a discussion on bitfields within the C++ Programming forums, part of the General Programming Boards category; Suppose I did this: Code: struct Stuff { var : 1 var2 : 4 unused : 3 }; Stuff stuff; ...
Suppose I did this:
Assuming the sytax is correct (not sure about thatCode:struct Stuff { var : 1 var2 : 4 unused : 3 }; Stuff stuff;), could I say "stuff.var = true;"? And then, could I manipulate var2 as an int?
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
The syntax is incorrect, but yeah, you are on the right track. You still have to give your struct members datatypes! Also, You don't need to put in the "unused" 3 bit wide variable (unless you are planning on using it, , which i'm doubting from the name, or for some reason just want those 3 bits to be of a certain value). Your structure will automatically be padded, just like any other case.
Also, it appears as though you want var to be used as a bool. You can declare it as a bool then!Code:struct Stuff { int var : 1, var2 : 4, unused : 3; };
Is all you need.Code:struct Stuff { bool var : 1; int var2 : 4; };
Oh, I get itso you still need the type to tell it how to handle the variables, right?
Oh, and by the way, the variable size is in bits, right (i.e. "bitfields")?
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.