Skip to content

Instantly share code, notes, and snippets.

// Ref: https://old.reddit.com/r/C_Programming/comments/1pxat1v
#include <assert.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#define new(a, n, t) (t *)alloc(a, n, sizeof(t), _Alignof(t))
typedef struct Dtor Dtor;
@skeeto
skeeto / demo.c
Last active December 21, 2025 17:29
Physics demo
// $ eval cc -g3 -o demo demo.c $(pkg-config --cflags --libs sdl2)
// Ref: https://old.reddit.com/r/C_Programming/comments/1prwizy
// Ref: https://github.com/Avery-Personal/Jubi
#define JUBI_IMPLEMENTATION
#include "Jubi.h"
#include "SDL.h"
static Sint32 randn(Uint64 *s, Sint32 lo, Sint32 hi)
{
*s = *s*0x3243f6a8885a308d + 1;
@skeeto
skeeto / baseline.c
Last active December 20, 2025 17:42
Baseline for a benchmark
// https://old.reddit.com/r/C_Programming/comments/1pr881z/
// $ cc -std=gnu23 -O -o baseline baseline.c
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@skeeto
skeeto / example.c
Last active December 17, 2025 16:32
// https://old.reddit.com/r/C_Programming/comments/1pnh9fq
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define S(s) (Str){s, sizeof(s)-1}
#define new(a, n, t) (t *)alloc(a, n, sizeof(t), _Alignof(t))
@skeeto
skeeto / exebuf.s
Created December 12, 2025 19:43
WNDPROC trampolines
.section .exebuf,"bwx"
.globl exebuf
exebuf: .space 1<<21
@skeeto
skeeto / exebuf.s
Last active December 12, 2025 01:34
.section .exebuf,"bwx"
.globl exebuf
exebuf: .space 1<<12
// Ref: https://old.reddit.com/r/C_Programming/comments/1oqxeeq
// This is free and unencumbered software released into the public domain.
#include <math.h>
#include <stdio.h>
#define lenof(a) (int)(sizeof(a) / sizeof(*(a)))
typedef struct { float x, y; } V2;
typedef struct { float x, y, z; } V3;
@skeeto
skeeto / cube.asm
Created October 3, 2025 16:18
spinning cube in assembly
; Assemble:
; $ nasm -fwin32 cube.asm
; Link with Mingw-w64:
; $ cc -mwindows -o cube.exe cube.obj libglfw3.a -lglu32 -lopengl32
; Link with MSVC:
; $ link /subsystem:windows cube.obj glfw3.lib opengl32.lib glu32.lib user32.lib gdi32.lib shell32.lib
;
; This is free and unencumbered software released into the public domain.
bits 32
// Assumes input is a 1080x1527 PPM with minimal header named maze.ppm.
// Outputs output.ppm with the solution drawn on top, and maze.txt with
// the raw maze structure.
//
// This is free and unencumbered software released into the public domain.
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
@skeeto
skeeto / Makefile
Last active October 20, 2025 07:02
skeetocrt example CRT
ALL = skeetocrt.dll skeetocrt.dll.a crt0.o
all: $(ALL)
skeetocrt.dll skeetocrt.dll.a: skeetocrt.c stdio.h
cc -shared -g3 -fno-builtin -nostartfiles --entry=0 \
-Wl,--out-implib=skeetocrt.dll.a -o skeetocrt.dll skeetocrt.c
crt0.o: crt0.c stdio.h
cc -c -g3 -fno-builtin -nostdlib -nostdinc -isystem . -o crt0.o crt0.c