this post was submitted on 15 May 2025
1159 points (98.7% liked)

Programmer Humor

23442 readers
301 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
 
(page 4) 16 comments
sorted by: hot top controversial new old
[–] [email protected] 6 points 1 week ago

This guy never coded in KEIL C on an 8051 architecture. They actually use bit addressable RAM for booleans. And if you set the compiler to pass function parameters in registers, it uses the carry flag for the first bit or bool type parameter.

[–] [email protected] 95 points 1 week ago (2 children)

string boolEnable = "True";

load more comments (2 replies)
[–] [email protected] 22 points 1 week ago (1 children)

Joke’s on you, I always use 64 bit wide unsigned integers to store a 1 and compare to check for value.

load more comments (1 replies)
[–] [email protected] 134 points 1 week ago (4 children)

I set all 8 bits to 1 because I want it to be really true.

[–] [email protected] 93 points 1 week ago* (last edited 1 week ago) (18 children)

01111111 = true

11111111 = negative true = false

load more comments (18 replies)
[–] [email protected] 10 points 1 week ago

You jest, but on some older computers, all ones was the official truth value. Other values may also have been true in certain contexts, but that was the guaranteed one.

[–] [email protected] 15 points 1 week ago (1 children)

TIL, 255 is the new 1.

Aka -1 >> 1 : TRUE

[–] [email protected] 8 points 1 week ago

But only if you really mean it. If not, it's a syntax error and the compiler will know.

load more comments (1 replies)
[–] [email protected] 33 points 1 week ago (2 children)

std::vector<bool> fits eight booleans into one byte.

load more comments (2 replies)
[–] [email protected] 22 points 1 week ago* (last edited 1 week ago) (1 children)

I have a solution with a bit fields. Now your bool is 1 byte :

struct Flags {
    bool flag0 : 1;
    bool flag1 : 1;
    bool flag2 : 1;
    bool flag3 : 1;
    bool flag4 : 1;
    bool flag5 : 1;
    bool flag6 : 1;
    bool flag7 : 1;
};

Or for example:

struct Flags {
    bool flag0 : 1;
    bool flag1 : 1:
    int x_cord : 3;
    int y_cord : 3;
};
load more comments (1 replies)
[–] [email protected] 91 points 1 week ago (10 children)

Then you need to ask yourself: Performance or memory efficiency? Is it worth the extra cycles and instructions to put 8 bools in one byte and & 0x bitmask the relevant one?

[–] [email protected] 37 points 1 week ago

Sounds like a compiler problem to me. :p

load more comments (9 replies)
[–] [email protected] 184 points 1 week ago (5 children)
typedef struct {
    bool a: 1;
    bool b: 1;
    bool c: 1;
    bool d: 1;
    bool e: 1;
    bool f: 1;
    bool g: 1;
    bool h: 1;
} __attribute__((__packed__)) not_if_you_have_enough_booleans_t;
[–] [email protected] 44 points 1 week ago

You beat me to it!

load more comments (4 replies)
[–] [email protected] 141 points 1 week ago (1 children)
[–] [email protected] 155 points 1 week ago (15 children)

And compiler. And hardware architecture. And optimization flags.

As usual, it's some developer that knows little enough to think the walls they see around enclose the entire world.

load more comments (15 replies)
load more comments
view more: ‹ prev next ›