Skip to content

Instantly share code, notes, and snippets.

View mattiasgustavsson's full-sized avatar
💾

Mattias Gustavsson mattiasgustavsson

💾
View GitHub Profile
@mattiasgustavsson
mattiasgustavsson / main.c
Created March 5, 2024 19:18
Minimal code example for creating a window to plot pixels to
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <windows.h>
#pragma comment( lib, "user32.lib" )
#pragma comment( lib, "gdi32.lib" )
#define SCRW 640
#define SCRH 480
@mattiasgustavsson
mattiasgustavsson / gist:b97e9e59e5e1742dcabff60179fcda67
Created April 7, 2022 14:13
Simple string allocation system, allowing for freeing all allocated strings in one go
#define STR_NEW( pool, str ) ( pool = memcpy( (char*) memcpy( malloc( ( str ? strlen( str ) : 0 ) + 1 + \
sizeof( char* ) ), &pool, sizeof( char* ) ) + sizeof( char*), str ? str : "", ( str ? strlen( str ) : 0 ) + 1 ) )
#define STR_FREE( pool ) while( pool ) { char* STR_FREE_TMP = ( pool - sizeof( char* ) ); \
pool = ( *(char**)STR_FREE_TMP ); free( STR_FREE_TMP ); }
//---------------------------
char* strpool = NULL;