Robert Edmonds on Nostr: Oh, huh. Not sure why I thought that would work. ``` #include <stdbool.h> #include ...
Oh, huh. Not sure why I thought that would work.
```
#include <stdbool.h>
#include <stdio.h>
union u {
char __please_gcc_15_zero_all_these_bits_not_just_some_of_them__[sizeof(union u)];
bool a;
char b;
short c;
int d;
};
int main(void)
{
union u foo = {0};
printf("union has %zd bytes:\n", sizeof(union u));
for (size_t i = 0; i < sizeof(foo); i++) {
printf("%02x ", *(((unsigned char *)&foo) + i));
}
putchar('\n');
return 0;
}
```
```
#include <stdbool.h>
#include <stdio.h>
union u {
char __please_gcc_15_zero_all_these_bits_not_just_some_of_them__[sizeof(union u)];
bool a;
char b;
short c;
int d;
};
int main(void)
{
union u foo = {0};
printf("union has %zd bytes:\n", sizeof(union u));
for (size_t i = 0; i < sizeof(foo); i++) {
printf("%02x ", *(((unsigned char *)&foo) + i));
}
putchar('\n');
return 0;
}
```