Skip to content
DevMeme
1504 of 7435
The Moral Alignment of C/C++ Main Functions
Languages Post #1684, on Jun 11, 2020 in TG

The Moral Alignment of C/C++ Main Functions

Description

A 3x3 alignment chart meme that humorously categorizes different ways of writing the `main` function signature in C/C++ according to the Dungeons & Dragons moral alignment system. Each of the nine squares contains an alignment label (e.g., 'LAWFUL GOOD', 'NEUTRAL EVIL') in a serif font, followed by a code snippet with syntax highlighting. The signatures range from the perfectly standard `int main(int argc, char *argv[])` (Lawful Good) and the slightly different but correct `int main(int argc, char** argv)` (Neutral Good), to the archaic K&R C style (Chaotic Good). It also includes common but less precise forms like `main()` (True Neutral). The 'Evil' alignments feature incorrect or non-standard practices: `void main()` (Neutral Evil), which violates the required integer return type, and a non-standard signature with environment variables (Lawful Evil). The chart culminates in 'CHAOTIC EVIL', which depicts `main` being defined as a constant integer array initialized with random numbers, a completely nonsensical and malicious piece of code. This meme resonates deeply with C/C++ developers, as it cleverly maps coding styles - from standards-compliant to dangerously incorrect - onto a familiar cultural template, judging them on axes of correctness and adherence to convention

Comments

7
Anonymous ★ Top Pick The Chaotic Evil definition of main() is how you get the compiler to file a restraining order against you
  1. Anonymous ★ Top Pick

    The Chaotic Evil definition of main() is how you get the compiler to file a restraining order against you

  2. Anonymous

    I used to flag `void main()` as a P1, but after inheriting a service where `const int main[] = { … }` gets `((void(*)())main)()`-invoked at runtime, my new incident playbook reads: 1) git rm --repo -rf, 2) exorcise the build server

  3. Anonymous

    The real chaotic evil is the developer who ships this to production and then argues in code review that returning -443987883 is actually a clever way to encode the build timestamp in the exit code

  4. Anonymous

    This alignment chart perfectly captures the eternal struggle between standards compliance and 'it compiles on my machine.' The 'Chaotic Evil' entry - declaring main as a const int array filled with what appears to be shellcode - is the programming equivalent of summoning an elder god: technically possible in some dark corner of the spec, but doing so means you've abandoned all hope of portability, sanity, and ever getting your code through a security review. Meanwhile, the 'void main()' crowd sits in 'Neutral Evil,' blissfully unaware that their code has been silently angering compiler writers since 1989

  5. Anonymous

    In code review I skip the culture deck and look at main: int main(void) says “we read the Standard,” int main() says “we trust the ABI,” void main() says “we worship Undefined Behavior,” and const int main[] says “we’ve started gaslighting the linker.”

  6. Anonymous

    Lawful good compiles and links; chaotic evil still parses, but when the ABI can’t resolve _start→main, ld becomes your on‑call SRE

  7. Anonymous

    Lawful Good passes -pedantic; Chaotic Evil segfaults gloriously in prod after years of 'it works'

Use J and K for navigation