Skip to content

Instantly share code, notes, and snippets.

// 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 September 18, 2025 01: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
@skeeto
skeeto / queue.c
Created September 11, 2025 16:52
#include <assert.h>
#include <pthread.h>
#include <stdint.h>
#include <stdlib.h>
#define lenof(a) (int)(sizeof(a) / sizeof(*(a)))
typedef uint16_t QueueUint;
typedef struct {
--- a/SRC/IO.H
+++ b/SRC/IO.H
@@ -3,3 +3,3 @@
-#include <_defs.h>
+//#include <_defs.h>
--- a/SRC/PSYMANDL.C
+++ b/SRC/PSYMANDL.C
@@ -1,4 +1,4 @@
// $ eval cc main_sdl2.c $(pkg-config --cflags --libs sdl2) -lm
char *SDL_itoa(int, char *, int);
#undef main // undo SDL_main from pkg-config
#define main appmain
#define itoa SDL_itoa
#include "SRC/AABB.C"
#include "SRC/BALL.C"
#include "SRC/BREAKOUT.C"
#include "SRC/GAMELVL.C"
// $ cc -g3 -fsanitize=thread,undefined test.c
//
// No data races detected because the mutex is unnecessary. To verify TSan
// is indeed working, modify newqueue to initialize improperly, such as
// setting a zero field to non-zero. This will cause a data race.
#define lenof(a) (int)(sizeof(a) / sizeof(*(a)))
typedef struct {
int count;
#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))
global _start
_start:
mov rdi, rsp
xor r10d, r10d
lea r13, [rel nl]
push r12
push rbp
push rbx
mov rbx, rdi
sub rsp, 1040
// https://old.reddit.com/r/C_Programming/comments/1l1hxeu
#include <assert.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define S(s) (Str){s, sizeof(s)-1}
typedef struct {
@skeeto
skeeto / demo.c
Last active August 3, 2025 23:11
N3037 showcase
// Requires GNU C23: GCC >= 15 or Clang >= 21
#include <stddef.h>
#include <string.h>
#define affirm(c) while (!(c)) unreachable()
#define lenof(a) (iz)(sizeof(a) / sizeof(*(a)))
#define new(a, n, t) (t *)alloc(a, n, sizeof(t), _Alignof(t))
#define maxof(t) ((t)-1<1 ? (((t)1<<(sizeof(t)*8-2))-1)*2+1 : (t)-1)
#define S(s) (Str){(u8 *)s, lenof(s)-1}