You said you can’t read one byte. I showed that you can. Where’s the confusion?
- 1 Post
- 15 Comments
My favourite closed question is how to do Case-insensitive string comparison in C++ - closed as opinion based!
ChatGPT helped, but this is why you died StackOverflow.
I disagree. I still easily find new questions to ask, for example this one which is a nice demonstration of why StackOverflow is dying. Or this one (which also received 4 downvotes).
Even so, I definitely go to ChatGPT first now. Now that we finally have an alternative to the toxic downvotes/closing, why would I go there unless I absolutely need to?
I think he’s talking about if a variable only exists in registers. In which case it is the size of a register. But that’s true of everything that gets put in registers. You wouldn’t say
uint16_t
is word-sized because at some point it gets put into a word-sized register. That’s dumb.
things that store it as word size for alignment purposes
Nope. bools only need to be naturally aligned, so 1 byte.
If you do
struct SomeBools { bool a; bool b; bool c; bool d; };
its 4 bytes.
The biggest problem is that each element doesn’t have a unique memory address; iterators aren’t just pointers.
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’slb
(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.
timhh@programming.devto Programmer Humor@programming.dev•Which of these javascript expressions is false?4·4 days agoI’m guessing there’s a reason they wanted min() to be able to be called without any arguments but I’m sure it isn’t a good one.
It not a totally unreasonable definition. For example it preserves nice properties like
min(a.concat(b)) == min([min(a), min(b)])
.Obviously the correct thing to do is to return an optional type, like Rust does. But … yeah I mean considering the other footguns in Javascript (e.g. the insane implicit type coersion) I’d say they didn’t do too badly here.
timhh@programming.devto Programmer Humor@programming.dev•Which of these javascript expressions is false?2·4 days agoCompletely wrong. I’m hoping this was a joke… :-D
You can’t store data in parity bits… so it’s irrelevant.
It’s not just less memory though - it might also introduce spurious data dependencies, e.g. to store a bit you now need to also read the old value of the byte that it’s in.
I don’t think so. Apart from dynamically typed languages which need to store the type with the value, it’s always 1 byte, and that doesn’t depend on architecture (excluding ancient or exotic architectures) or optimisation flags.
Which language/architecture/flags would not store a bool in 1 byte?
No it isn’t. All statically typed languages I know of use a byte. Which languages store it in an entire 32 bits? That would be unnecessarily wasteful.
Well there are containers that store booleans in single bits (e.g.
std::vector<bool>
- which was famously a big mistake).But in the general case you don’t want that because it would be slower.
Nope. - if you can’t read RISC-V assembly, look at these lines
sb a5,-17(s0) ... sb a5,-18(s0) ... sb a5,-19(s0) ...
That is it storing the bools in single bytes. Also I only used RISC-V because I’m way more familiar with it than x86, but it will do the same thing.
Nope, you can happily
malloc(1)
and store a bool in it, ormalloc(4)
and store 4 bools in it. A bool is 1 byte. Consider this a TIL moment.