1158
Tell me the truth ... (piefed.jeena.net)
you are viewing a single comment's thread
view the rest of the comments
[-] Aux@feddit.uk 1 points 6 days ago

It's not wasteful, it's faster. You can't read one byte, you can only read one word. Every decent compiler will turn booleans into words.

[-] timhh@programming.dev 0 points 3 days ago

You can’t read one byte

lol what. You can absolutely read one byte: https://godbolt.org/z/TeTch8Yhd

On ARM it's ldrb (load register byte), and on RISC-V it's lb (load byte).

Every decent compiler will turn booleans into words.

No compiler I know of does this. I think you might be getting confused because they're loaded into registers which are machine-word sized. But in memory a bool is always one byte.

[-] Aux@feddit.uk 1 points 3 days ago

Sorry, but you're very confused here.

[-] timhh@programming.dev 1 points 2 days ago

You said you can't read one byte. I showed that you can. Where's the confusion?

[-] Aux@feddit.uk 1 points 1 day ago

Internally it will still read a whole word. Because the CPU cannot read less than a word. And if you read the ARM article you linked, it literally says so.

Thus any compiler worth their salt will align all byte variables to words for faster memory access. Unless you specifically disable such behaviour. So yeah, RTFM :)

[-] timhh@programming.dev 0 points 1 day ago

Wrong again. It depends on the CPU. They can absolutely read a single byte and they will do if you're reading from non-idempotent memory.

If you're reading from idempotent memory they won't read a byte or a word. They'll likely read a whole cache line (usually 64 bytes).

And if you read the ARM article you linked, it literally says so.

Where?

Thus any compiler worth their salt will align all byte variables to words for faster memory access.

No they won't because it isn't faster. The CPU will read the whole cache line that contains the byte.

RTFM

Well, I would but no manual says that because it's wrong!

[-] Aux@feddit.uk 0 points 1 day ago

The fuck are you talking about, kiddo? Read the fucking docs!

[-] timhh@programming.dev 1 points 1 day ago* (last edited 1 day ago)

What docs? A bool is one byte. Get over it. Find me one normal compiler/architecture in C, C++, Go, Rust, Zig, etc. where it is not. Go on.

this post was submitted on 15 May 2025
1158 points (98.6% liked)

Programmer Humor

23417 readers
1777 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