Skip to content

Instantly share code, notes, and snippets.

View v-borg's full-sized avatar

Victor Borges v-borg

  • Freelancer
  • Passos, Minas Gerais
  • 06:53 (UTC -03:00)
View GitHub Profile
@v-borg
v-borg / function_overloading.c
Created April 4, 2024 18:19
Since the C11 standard, the C language offers the _Generic keyword, which acts as a compile-time switch and allows behavior similar to function overloading, which is common in C++.
// Note that functions initiated with static inline will be transformed into inline by the compiler
// (tested on gcc and clang), and yet, the _Generic keyword is capable of identifying them correctly.
//
// (https://godbolt.org/z/Mo4rYsKn1)
#include <math.h>
#include <stdio.h>
// global
@v-borg
v-borg / main.c
Created December 7, 2023 01:27
Simple FreeList allocator
// This allocation system is an old implementation I created inspired by the
// system used by DOOM. It employs a freelist-based approach to allocate memory
// in two different arenas. It is capable of allocating, deallocating,
// identifying double frees, and detecting corrupted memory pointers.
// Additionally, it can determine whether the pointer was returned by any of the
// available arenas.
// It is a straightforward implementation and has not undergone extensive
// testing, so there may be potential issues. However, I hope it proves useful
// to you in some way. Feel free to use and modify it as you see fit.
//
@v-borg
v-borg / bench.c
Created November 28, 2021 01:02
Benchmark between integers (with modifiers), float and double
#include <stdio.h>
#ifdef _WIN32
#include <sys/timeb.h>
#else
#include <sys/time.h>
#endif
#include <cstdlib>
#include <time.h>
double sillygettime(void) {
@v-borg
v-borg / create_tga_image.c
Created November 19, 2021 15:48
Writing a TGA image using a Lehmer Pseudo Random Number Generator implementation (modified) for 32bits
/*
* Writing a TGA image using a Lehmer Pseudo Random Number Generator
* implementation (modified) for 32bits
*
* How to compile:
* $ gcc *.c -o create_tga_image
*
* Binary options:
* You can change the image's width and height using the -w and -h flags,
* respectively. It is possible to adjust the x and y PRN salt used by