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
// Draw a triangle on Windows using OpenGL 1.1 | |
// $ gcc -mwindows -o triangle triangle.c -lopengl32 | |
// This is free and unencumbered software released into the public domain. | |
#define WIN32_LEAN_AND_MEAN | |
#include <windows.h> | |
#include <GL/gl.h> | |
#define countof(a) (int)(sizeof(a) / (sizeof(*(a)))) | |
static LRESULT CALLBACK handler(HWND h, UINT msg, WPARAM wparam, LPARAM lparam) |
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
// 8-bit indexed PNG writer, no dependencies | |
// $ cc -o png png.c | |
// $ ./png >image.png | |
// This is free and unencumbered software released into the public domain. | |
#include <stddef.h> | |
#include <stdint.h> | |
#include <stdio.h> | |
static uint32_t adler32(uint32_t sum, uint8_t *buf, ptrdiff_t len) | |
{ |
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
// "Two Sum" benchmark | |
// $ cc -O1 -nostartfiles -o twoSum.exe twoSum.c | |
// $ cl /O1 twoSums.c /link /subsystem:console kernel32.lib libvcruntime.lib | |
// Ref: https://old.reddit.com/r/C_Programming/comments/1c36391 | |
#include <stddef.h> | |
#include <stdint.h> | |
#include <string.h> | |
#define assert(c) while (!(c)) *(volatile int *)0 = 0 | |
#define new(a, t, n) (t *)alloc(a, sizeof(t), _Alignof(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
// x86-64 Linux buffered "hello world" | |
// $ cc example.c && ./a.out | |
// Ref: https://old.reddit.com/r/C_Programming/comments/1bxvs3u | |
// Ref: https://thecoder08.github.io/hello-world.html | |
// Ref: https://nullprogram.com/blog/2023/02/13/ | |
#include <stddef.h> | |
#include <string.h> | |
ptrdiff_t xwrite(int fd, void *buf, ptrdiff_t len) | |
{ |
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 -o persona persona.c | |
// $ ./persona <test.txt | |
// Ref: https://old.reddit.com/r/C_Programming/comments/1bmfb7p | |
#include <stddef.h> | |
#include <stdint.h> | |
#include <string.h> | |
#define assert(c) while (!(c)) *(volatile int *)0 = 0 | |
#define countof(a) (ptrdiff_t)(sizeof(a) / sizeof(*(a))) | |
#define new(a, t, n) (t *)alloc(a, sizeof(t), _Alignof(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
// Ref: https://old.reddit.com/r/golang/comments/1bcfe95/slice_as_map_key_in_go/ | |
package main | |
import ( | |
"encoding/binary" | |
"fmt" | |
"math/rand" | |
"slices" | |
"strings" | |
"testing" |
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
// Font rendering demo | |
// $ cc -o demo demo.c $(sdl2-config --cflags --libs) | |
// Ref: https://old.reddit.com/r/C_Programming/comments/13ga82a | |
// This is free and unencumbered software released into the public domain. | |
#include "SDL.h" | |
// https://itch.io/jam/lowrezjam2016/topic/19413/minimal-sprite-font-with-upperlower-cases-cleanreadable | |
#define FONTW 72 | |
#define FONTH 143 | |
#define CHARW 9 |
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 -o graph graph.c | |
// $ ./a.out | |
// Ref: https://old.reddit.com/r/roguelikedev/comments/1b7pa9w/ | |
#include <stdio.h> | |
static int rand31(unsigned long long *s) | |
{ | |
*s = *s*0x3243f6a8885a308dU + 1; | |
return (int)(*s >> 33); | |
} |
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
// WriteProcessMemory demo | |
// $ cc -nostartfiles -o demo.exe demo.c | |
// $ cl demo.c /link /subsystem:console kernel32.lib | |
// This is free and unencumbered software released into the public domain. | |
#include <stddef.h> | |
#define countof(a) (ptrdiff_t)(sizeof(a) / sizeof(*(a))) | |
typedef unsigned char u8; | |
typedef signed int b32; |
NewerOlder