Skip to content

Instantly share code, notes, and snippets.

@anish-lakkapragada
Created December 25, 2024 12:52
Show Gist options
  • Select an option

  • Save anish-lakkapragada/6794d17840ebad4d79421a4be933b7a8 to your computer and use it in GitHub Desktop.

Select an option

Save anish-lakkapragada/6794d17840ebad4d79421a4be933b7a8 to your computer and use it in GitHub Desktop.
Hinduism in 75 lines of C
/**
* This is an executable C program that tries to capture major Hinduism deities in
* less than 100 lines of code. I tried to make the code as artistic as possible while
* maintaining C compilability. Please contact [email protected] for any
* corrections or grievances.
*/
#include <stdio.h>
#include <stdlib.h>
// Holy Trimurthi Macros.
#define Brahma(size) malloc(size) // the Creator
#define Vishnu(ptr, size) realloc(ptr, size) // the Preserver
#define Shiva(ptr) free(ptr) // the Destroyer
#define Yama() exit(0) // God of Death
typedef struct God {
struct God *father;
struct God *mother;
struct God *husband;
struct God *wife;
} God;
typedef struct God Avatar;
int main(int argc, char **argv) {
// For readability
size_t _ = sizeof(God);
God *__ = malloc(_);
size_t ___ = sizeof(Avatar);
Avatar *____ = malloc(___);
God *_____ = malloc(_);
// The heap is heaven, where the Tridevi and all deities reside
God *Lakshmi = __;
Lakshmi->husband = Vishnu(__, _);
God *Saraswati = __;
Saraswati->husband = Brahma(_);
God *Parvati = __;
Shiva(Parvati->husband);
God *Durga = _____;
Shiva(Durga->husband);
God *Ganesha = __;
Ganesha->mother = Parvati;
Shiva(Ganesha->father);
God *Kartikeya = __;
Kartikeya->mother = Parvati;
Shiva(Kartikeya->father);
God *Hanuman = __;
// Avatars live on the stack
Avatar Balaji, Venkateswara, Srinivasa;
Balaji = Venkateswara = Srinivasa = *(Avatar*) Vishnu(____, ___);
Avatar Padmavati = *Lakshmi;
Balaji.wife = &Padmavati; Padmavati.husband = &Balaji;
Avatar Rama = *(Avatar*) Vishnu(____, ___);
Avatar Sita = *Lakshmi;
Rama.wife = &Sita; Sita.husband = &Rama;
Avatar Krishna = *(Avatar*) Vishnu(____, ___);
Krishna.wife = malloc(_ * (16000 + 8));
Avatar Radha = *Lakshmi;
Radha.husband = &Krishna;
// Please forgive memory leaks
Yama();
}
@Alluseri
Copy link

now make naraka (thread local storage)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment