r/ProgrammerHumor • • Oct 07 '26

Meme wasteOfPreciousSpace

Post image
7.3k Upvotes

244 comments sorted by

View all comments

-1

u/Alacritous13 Oct 08 '26

I don't get it? As long as you define the bools next to each other, they'll fill up the byte before moving on to the next. How it works on a PLC at least, I don't know of anything else that could care about this level of inefficiency.

6

u/dev-sda Oct 08 '26

That's not how it works in the majority of low level programming languages; the primary reason for that is that single bits aren't addressable.

As far as I can tell that's also true in PLC-land. Structured Text dictates BOOL has a logical size of 1 bit, but both codesys and beckhoff use a full byte. C and C++ will also use a full byte. There's ways to pack bits, but it usually comes at the cost of addressability.

1

u/Alacritous13 Oct 08 '26

Well, codesys can bite my ass. But I've got no beef with beckhoff, they seem alright.

1

u/QuillnSofa Oct 08 '26

Mmmm bit shifting is magic

3

u/ubergeek801 Oct 08 '26

Some compilers (languages?) make this optimization; others... don't.

5

u/Kerbourgnec Oct 08 '26

Polish Lithuanian Commonwealth mentionned 🇵🇱🇵🇱🐦‍🔥🐦‍🔥🇱🇹🇱🇹

2

u/YoteTheRaven Oct 08 '26

That is not how it works in a non-PLC, I guess.

2

u/fbpw131 Oct 08 '26

a bool is stored using a byte or whatever is adressable.

2

u/nitkonigdje Oct 08 '26

Boolean in Java is 24 bytes large.

They did optimize it in the very latest version. It took them 30 years to tuned it down to 16 bytes.