This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Parse /proc/meminfo into a hash map | |
// This is free and unencumbered software released into the public domain. | |
#include <fcntl.h> | |
#include <stddef.h> | |
#include <stdint.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <unistd.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Advent of Code 2023 Day 15 | |
// https://adventofcode.com/2023/day/15 | |
// https://nrk.neocities.org/articles/aoc23 | |
// This is free and unencumbered software released into the public domain. | |
#include <stddef.h> | |
#include <string.h> | |
#define assert(c) while (!(c)) *(volatile int *)0 = 0 | |
#define new(a, t, n) (t *)alloc(a, sizeof(t)*n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Gradual-commit arena demonstration | |
// This is free and unencumbered software released into the public domain. | |
#include <stddef.h> | |
#include <string.h> | |
static void *os_reserve(ptrdiff_t); | |
static _Bool os_commit(void *, ptrdiff_t); | |
#define ARENA_PAGESIZE ((ptrdiff_t)1<<26) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// $ cc -mwindows stretchdibits.c | |
#include <windows.h> | |
enum { | |
WIDTH = 1280, | |
HEIGHT = 720, | |
}; | |
static unsigned char *pixels; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stddef.h> | |
#include <stdint.h> | |
#define assert(c) while (!(c)) *(volatile int *)0 = 0 | |
#define countof(a) (size)(sizeof(a) / sizeof(*(a))) | |
#define new(a, t, n) (t *)alloc(a, sizeof(t), _Alignof(t), n) | |
typedef int32_t b32; | |
typedef uint32_t u32; | |
typedef uint64_t u64; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _GNU_SOURCE | |
#include <assert.h> | |
#include <fcntl.h> | |
#include <stdint.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <sys/mman.h> | |
#include <unistd.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <windows.h> | |
#define new(a, t, n) (t *)alloc(a, sizeof(t)*n) | |
typedef struct { | |
char *beg, *end; | |
} arena; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum { | |
BASE = 1000000000, // nine decimals per limb | |
NUMCAP = 1<<16, // capacity just over a half million decimals | |
}; | |
typedef struct { | |
int *digits; | |
int len; | |
} num; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stddef.h> | |
#include <stdint.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define assert(c) while (!(c)) *(volatile int *)0 = 0 | |
#define new(a, t) (t *)alloc(a, sizeof(t)) | |
typedef struct { | |
char *beg, *end; |