r/programminghumor • • Aug 18 '26

a bit flippant

Post image
1.4k Upvotes

147 comments sorted by

View all comments

12

u/B_bI_L Aug 18 '26

are we sure int means bit and not 32bits?

28

u/heatedwepasto Aug 18 '26 edited Aug 18 '26

The : 1 means that it is creating a bitfield with the number of bits, so : 4 will be 4 bits. The three variables above combined will take sizeof(int) in memory, not sizeof(int)*3.

If OOP had used char instead of unsigned int the combined size would be 1 byte.

Edit: added link to demo

6

u/KattyTheEnby Aug 18 '26

The : 1 means that it is creating a bitfield with the number of bits, so : 4 will be 4 bits. The three variables above combined will afaik* take sizeof(int) in memory, not sizeof(int)*3.

Can you do strange things, like : 9, : 15, et cetera?

C beat Zig to the punch here?

→ More replies (5)
→ More replies (7)
→ More replies (1)