Either I don't understand what you're saying or you're misunderstanding the notation. Each line declares a struct member of type unsigned int which is 1 bit large. It's not setting it to 1 (true).
It’s probably about the fact that json is flexible data that gets parsed while this struct has strict alignments and depends on the ABI it’s compiled on. And because it’s compiled against an ABI, if the server struct was compiled with a different ABI, the server and client struct could be completely different structs making them incompatible.
I mean if you have a serializer and deserializer you could definitely do that, I don’t see a problem there is well. It’s just about that you cannot send the actual raw struct but always have to send a custom format both can understand. I don’t think it’s more than that.
I think he's just showing that each field in 1 bit long. The only caveat with this is that most C compilers will pad this struct out to the size of an int. (Typically 32 bits, or 4 bytes). He would have to add __attribute__((packed)) to the end of the struct before the semicolon. Then sizeof(struct Flags) would be 1 byte.
struct MyOptions is 8 bytes because the compiler added 3 padding bytes in between flags and max_of_something. If you made MyOptions a packed struct as well, then it'd be 5 bytes:
#include <stdio.h>
#include <stdint.h>
struct Flags {
unsigned int a : 1;
unsigned int b : 1;
unsigned int c : 1;
unsigned int d : 1;
} __attribute__((packed));
struct MyOptions {
struct Flags flags;
int32_t something;
} __attribute__((packed));
int main(void)
{
/* The output is 5 */
printf("%zu\n", sizeof(struct MyOptions));
return 0;
}
View all comments
200
u/consistently_biased Aug 18 '26
Can I use this for my compile-time https server?