Created
June 28, 2025 11:32
-
-
Save cacharle/d224475c2f50fe7c029f8e65b1c3fb81 to your computer and use it in GitHub Desktop.
bit_field_minimum_size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
struct withshort | |
{ | |
short c : 4; | |
short c2 : 4; | |
short c3 : 1; | |
short c4 : 7; | |
}; | |
struct withint | |
{ | |
int c : 4; | |
int c2 : 4; | |
int c3 : 1; | |
int c4 : 7; | |
}; | |
struct withlong | |
{ | |
long c : 4; | |
long c2 : 4; | |
long c3 : 1; | |
long c4 : 7; | |
}; | |
int main() | |
{ | |
printf("withshort size = %zu\n", sizeof(struct withshort)); | |
printf("withint size = %zu\n", sizeof(struct withint)); | |
printf("withlong size = %zu\n", sizeof(struct withlong)); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
withshort size = 2 | |
withint size = 4 | |
withlong size = 8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment