1109
Tell me the truth ... (piefed.jeena.net)
you are viewing a single comment's thread
view the rest of the comments
[-] skisnow@lemmy.ca 4 points 1 day ago* (last edited 22 hours ago)

The code is a set of preprocessor macros to stuff loads of booleans into one int (or similar), in this case named 'myFlags'. The preprocessor is a simple (some argue too simple) step at the start of compilation that modifies the source code on its way to the real compiler by substituting #defines, prepending #include'd files, etc.

If myFlags is equal to, e.g. 67, that's 01000011, meaning that BV00, BV01, and BV07 are all TRUE and the others are FALSE.

The first part is just for convenience and readability. BV00 represents the 0th bit, BV01 is the first etc. (1 << 3) means 00000001, bit shifted left three times so it becomes 00001000 (aka 8).

The middle chunk defines macros to make bit operations more human-readable.

SET_BIT(myFlags, MY_FIRST_BOOLEAN) gets turned into ((myFlags) |= ((1 << 0))) , which could be simplified as myFlags = myFlags | 00000001 . (Ignore the flood of parentheses, they're there for safety due to the loaded shotgun nature of the preprocessor.)

this post was submitted on 15 May 2025
1109 points (100.0% liked)

Programmer Humor

23310 readers
1130 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