▲ 1168 ▼ Tell me the truth ... (europe.pub) submitted 1 year ago by cm0002@lemmy.world to c/programmer_humor@programming.dev 170 comments fedilink hide all child comments
[–] savedbythezsh@sh.itjust.works 14 points 1 year ago (10 children) Are you telling me that no compiler optimizes this? Why? permalink fedilink source hideshow 10 child comments replies: [–] Anders429@programming.dev 35 points 1 year ago It would be slower to read the value if you had to also do bitwise operations to get the value. But you can also define your own bitfield types to store booleans packed together if you really need to. I would much rather that than have the compiler do it automatically for me. permalink fedilink source parent [–] timhh@programming.dev 24 points 1 year ago (4 children) 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. permalink fedilink source parent hideshow 4 child comments replies: [–] ethancedwards8@programming.dev 7 points 1 year ago (3 children) Why is this a big mistake? I’m not a c++ person permalink fedilink source parent hideshow 3 child comments replies: [–] bitcrafter@programming.dev 5 points 1 year ago (2 children) The mistake was that they created a type that behaves like an array in every case except for bool, for which they created a special magical version that behaves just subtly different enough that it can break things in confusing ways. permalink fedilink source parent hideshow 2 child comments replies: [–] ethancedwards8@programming.dev 2 points 1 year ago (1 child) Could you provide an example? permalink fedilink source parent hideshow 1 child comment replies: [–] timhh@programming.dev 1 point 1 year ago The biggest problem is that each element doesn't have a unique memory address; iterators aren't just pointers. permalink fedilink source parent [–] gamer@lemm.ee 5 points 1 year ago* (last edited 1 year ago) (1 child) Consider what the disassembly would look like. There's no fast way to do it. It's also unnecessary since 8 bytes is a negligible amount in most cases. Serialization is the only real scenario where it matters. (Edit: and embedded) permalink fedilink source parent hideshow 1 child comment replies: [–] Croquette@sh.itjust.works 5 points 1 year ago In embedded, if you are to the point that you need to optimize the bools to reduce the footprint, you fucked up sizing your mcu. permalink fedilink source parent [–] Jankatarch@lemmy.world 4 points 1 year ago CPUs don't read one bit a a time. permalink fedilink source parent [–] Aux@feddit.uk 0 points 1 year ago They do, that's the optimisation. permalink fedilink source parent
[–] Anders429@programming.dev 35 points 1 year ago It would be slower to read the value if you had to also do bitwise operations to get the value. But you can also define your own bitfield types to store booleans packed together if you really need to. I would much rather that than have the compiler do it automatically for me. permalink fedilink source parent
[–] timhh@programming.dev 24 points 1 year ago (4 children) 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. permalink fedilink source parent hideshow 4 child comments replies: [–] ethancedwards8@programming.dev 7 points 1 year ago (3 children) Why is this a big mistake? I’m not a c++ person permalink fedilink source parent hideshow 3 child comments replies: [–] bitcrafter@programming.dev 5 points 1 year ago (2 children) The mistake was that they created a type that behaves like an array in every case except for bool, for which they created a special magical version that behaves just subtly different enough that it can break things in confusing ways. permalink fedilink source parent hideshow 2 child comments replies: [–] ethancedwards8@programming.dev 2 points 1 year ago (1 child) Could you provide an example? permalink fedilink source parent hideshow 1 child comment replies: [–] timhh@programming.dev 1 point 1 year ago The biggest problem is that each element doesn't have a unique memory address; iterators aren't just pointers. permalink fedilink source parent
[–] ethancedwards8@programming.dev 7 points 1 year ago (3 children) Why is this a big mistake? I’m not a c++ person permalink fedilink source parent hideshow 3 child comments replies: [–] bitcrafter@programming.dev 5 points 1 year ago (2 children) The mistake was that they created a type that behaves like an array in every case except for bool, for which they created a special magical version that behaves just subtly different enough that it can break things in confusing ways. permalink fedilink source parent hideshow 2 child comments replies: [–] ethancedwards8@programming.dev 2 points 1 year ago (1 child) Could you provide an example? permalink fedilink source parent hideshow 1 child comment replies: [–] timhh@programming.dev 1 point 1 year ago The biggest problem is that each element doesn't have a unique memory address; iterators aren't just pointers. permalink fedilink source parent
[–] bitcrafter@programming.dev 5 points 1 year ago (2 children) The mistake was that they created a type that behaves like an array in every case except for bool, for which they created a special magical version that behaves just subtly different enough that it can break things in confusing ways. permalink fedilink source parent hideshow 2 child comments replies: [–] ethancedwards8@programming.dev 2 points 1 year ago (1 child) Could you provide an example? permalink fedilink source parent hideshow 1 child comment replies: [–] timhh@programming.dev 1 point 1 year ago The biggest problem is that each element doesn't have a unique memory address; iterators aren't just pointers. permalink fedilink source parent
[–] ethancedwards8@programming.dev 2 points 1 year ago (1 child) Could you provide an example? permalink fedilink source parent hideshow 1 child comment replies: [–] timhh@programming.dev 1 point 1 year ago The biggest problem is that each element doesn't have a unique memory address; iterators aren't just pointers. permalink fedilink source parent
[–] timhh@programming.dev 1 point 1 year ago The biggest problem is that each element doesn't have a unique memory address; iterators aren't just pointers. permalink fedilink source parent
[–] gamer@lemm.ee 5 points 1 year ago* (last edited 1 year ago) (1 child) Consider what the disassembly would look like. There's no fast way to do it. It's also unnecessary since 8 bytes is a negligible amount in most cases. Serialization is the only real scenario where it matters. (Edit: and embedded) permalink fedilink source parent hideshow 1 child comment replies: [–] Croquette@sh.itjust.works 5 points 1 year ago In embedded, if you are to the point that you need to optimize the bools to reduce the footprint, you fucked up sizing your mcu. permalink fedilink source parent
[–] Croquette@sh.itjust.works 5 points 1 year ago In embedded, if you are to the point that you need to optimize the bools to reduce the footprint, you fucked up sizing your mcu. permalink fedilink source parent
[–] Jankatarch@lemmy.world 4 points 1 year ago CPUs don't read one bit a a time. permalink fedilink source parent
[–] Aux@feddit.uk 0 points 1 year ago They do, that's the optimisation. permalink fedilink source parent