Skip to content

Instantly share code, notes, and snippets.

@Zelmoghazy
Zelmoghazy / prof.c
Created June 23, 2025 18:14
Very simple profiler in C
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>
#ifdef _WIN32
#include <windows.h>
#else
@Zelmoghazy
Zelmoghazy / c_declarations.c
Created February 26, 2025 20:38
How declarations work in C
int a; // a evaluates to int -> a is an int
int *a; // *a (dereferencing) evaluates to int -> a is a pointer to int
int a(); // a() evaluates to int -> a is a function that returns int
int *a(); // () has higher precedence ≃ int *(a()) -> deref a() evaluates to int -> a is a function that returns pointer to int
int (*a)(); // (*a)() evaluates to int -> a is a pointer to function that returns int
int a[10]; // a[i] evaluates to int -> a is an array of 10 integers
int *a[10]; // [] has higher precedence ≃ int *(a[10]) -> deref a[i] evaluates to int -> a is an array of 10 pointers to int
int (*a)[10]; // (*a)[i] evaluates to int -> a is a pointer to an array of 10 integers
@Zelmoghazy
Zelmoghazy / Makefile
Created February 8, 2025 20:54
Minimal Generic Makefile
CC=g++
EXT=cpp
OPT=
DBG=
WARNINGS=-Wall -Wextra -Wsign-conversion -Wconversion
STD=-std=c++17
DEPFLAGS=-MP -MD
DEF=
@Zelmoghazy
Zelmoghazy / enum_to_str.c
Last active February 8, 2025 13:02
Get the string representation of enums and iterate them in C using macros
#include <stdio.h>
#define ENUM_GEN(ENUM) ENUM,
#define STRING_GEN(STRING) #STRING,
// Add all your enums here
#define LIST_RET_T(RET_T) \
RET_T(RET_SUCCESS) \
RET_T(RET_FULL) \
RET_T(RET_EMPTY) \