Sign in to follow this  
Neon2302

question about struct

Recommended Posts

Simian Man    1022
It's a bit field.

The intent seems to be to create a boolean that takes up only 1 bit. I'm pretty sure, however, that the whole struct must take up at least a byte no matter what. Perhaps someone more knowledgeable can clarify.

Share this post


Link to post
Share on other sites
SiCrane    11839
Quote:
Original post by Crypter
Also, bit fields cannot be of type bool, although this may be compiler dependent.

Yes, they can. See section 9.6 paragraph 4 of the C++ standard.

Quote:
Original post by Simian Man
The intent seems to be to create a boolean that takes up only 1 bit. I'm pretty sure, however, that the whole struct must take up at least a byte no matter what. Perhaps someone more knowledgeable can clarify.

Yes, structs must always have a sizeof of at least 1.

Share this post


Link to post
Share on other sites
Crypter    748
Quote:
Original post by SiCrane
Quote:
Original post by Crypter
Also, bit fields cannot be of type bool, although this may be compiler dependent.

Yes, they can. See section 9.6 paragraph 4 of the C++ standard.

My mistake--you are absolutely correct. Thanks for pointing that out.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this