Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid booleans as struct fields #43

Open
erlingrj opened this issue Oct 7, 2024 · 3 comments
Open

Avoid booleans as struct fields #43

erlingrj opened this issue Oct 7, 2024 · 3 comments

Comments

@erlingrj
Copy link
Collaborator

erlingrj commented Oct 7, 2024

Good feedback from Edward. A boolean as a struct field wastes 31 bits. I think we can use C's ability to specify bitwidths as follows

struct MyStruct {
  bool first: 1;
  bool second: 1;
  int small_int:6
  int bigger_int:8
  int biggest_int:16
};

This should all fit in one 32bit word

@erlingrj erlingrj added the enhancement New feature or request label Oct 7, 2024
@edwardalee
Copy link
Collaborator

I don't think you can assume the compiler will put these in a 32-bit word. What I had in mind was more like this:

struct my_struct_t {
   int32_t flags;
   ...
}

Then have macros like FIRST(struct) and SECOND(struct) that you use in conditionals.

@erlingrj
Copy link
Collaborator Author

erlingrj commented Oct 8, 2024

Then what is the meaning of int a:4? I thought it was exactly for this purpose?

@edwardalee
Copy link
Collaborator

Oh, I don't know. I'm not familiar with that syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants