#How to allocate some memory to a variable inside of a struct

15 messages · Page 1 of 1 (latest)

tame kindle
#

I want to make only 2 bits wide variable inside of my struct and as i know even if i assign int it will take 8 bits of memory, which i can further deallocate to 2 bits, but still, at the start it will take space, how do i make only 2 bits wide type?

clever ore
#

int foo:2;

tame kindle
#

oh

clever ore
#

however, it's worth doing so only if you have additional such fields

#

without normal fields between them

#

otherwise, it's likely to take 4 bytes still

tame kindle
#

forgot to mention, i'm on C

clever ore
#

that is for C

tame kindle
#

does that work on non-struct?

clever ore
#

and C++

#

no

tame kindle
#

oh

clever ore
#

you can't allocate anything smaller than 1 byte

tame kindle
#

i know that