this post was submitted on 17 Jun 2023
66 points (100.0% liked)

Programmer Humor

19187 readers
1256 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 1 year ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] Speiser0@feddit.de 1 points 1 year ago

If people want me to write into my code what it does, I guess I'll label everything:

#include <iostream>
#include <cstdint>

#pragma GCC diagnostic ignored "-Wunused-label"

int main()
{
A:int a = 4;
B:if ((uintptr_t)&a & 0x100)
BA:std::cout << "hi" << std::endl; else
BB:std::cout << "hello" << std::endl;
C:return 0;
}

Note that this is much better for code style because - as opposed to the semicolon indentation- the single statement if and else branches still work. The trailing else is on the same line on purpose, it's so small it doesn't need its own line. Here's another style with similar properties:

[[,]]int a = 4;
[[,]]if ((uintptr_t)&a & 0x100)
[[,,]]std::cout << "hi" << std::endl; else
[[,]]std::cout << "hello" << std::endl;
[[,]]return 0;