this post was submitted on 15 May 2025
1132 points (98.5% liked)

Programmer Humor

23710 readers
2207 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] acockworkorange@mander.xyz 38 points 2 weeks ago (1 children)

In the industrial automation world and most of the IT industry, data is aligned to the nearest word. Depending on architecture, that's usually either 16, 32, or 64 bits. And that's the space a single Boolean takes.

[–] ZILtoid1991@lemmy.world 19 points 2 weeks ago (1 children)

That's why I primarily use booleans in return parameters, beyond that I'll try to use bitfields. My game engine's tilemap format uses a 32 bit struct, with 16 bit selecting the tile, 12 bit selecting the palette, and 4 bit used for various bitflags (horizontal and vertical mirroring, X-Y axis invert, and priority bit).

[–] acockworkorange@mander.xyz 29 points 2 weeks ago (4 children)

Bit fields are a necessity in low level networking too.

They're incredibly useful, I wish more people made use of them.

I remember I interned at a startup programming microcontrollers once and created a few bitfields to deal with something. Then the lead engineer went ahead and changed them to masked ints. Because. The most aggravating thing is that an int size isn't consistent across platforms, so if they were ever to change platforms to a different word length, they'd be fucked as their code was full of platform specific shenanigans like that.

/rant

[–] grrgyle@slrpnk.net 7 points 2 weeks ago
[–] ulterno@programming.dev 4 points 2 weeks ago (1 children)

Yeah. I once had to do stuff to code that had bit-fields like that and after a while, realised (by means of StackOverflow) that that part is UB and I had to go with bitwise operations instead.

[–] grrgyle@slrpnk.net 4 points 2 weeks ago (1 children)
[–] ulterno@programming.dev 1 points 2 weeks ago

Ok, I recalled wrong, it was unspecified

[–] Croquette@sh.itjust.works 3 points 2 weeks ago

I always use stdint.h so that my types are compatible across any mcu. And it makes the data type easily known instead of guessing an i t size

[–] jenesaisquoi@feddit.org 0 points 2 weeks ago

Or you could just use Rust