r/badcode • • Feb 02 '22

c# Oh hey, its more of my code.

Post image
902 Upvotes

95 comments sorted by

View all comments

Show parent comment

8

u/[deleted] Feb 03 '22

Not really, booleans are typically stored as a byte, and it's value can range from 0 - 255. 0 is false, and everything else is normally true. In this instance, everything but 1 is false.

3

u/RFC793 Feb 03 '22

What environment normally stores integers as a byte? Yes, it is never a “bit” as that isn’t addressable. More typically the machine’s word size, 32 bit, or the min(32, word size)…

10

u/[deleted] Feb 03 '22

Let's all be thankful that bit-endianess is generally only a headache of hardware developers.

1

u/Dumfing Feb 03 '22

And audio developers, and network developers

1

u/[deleted] Feb 03 '22

C++ stores booleans as a byte

6

u/RFC793 Feb 03 '22

Your comment originally said “ints” and you changed it to “booleans” after my reply.

But, yes, bool in C++ is explicitly defined as one byte.