Skip to content

Instantly share code, notes, and snippets.

View Eisenwave's full-sized avatar

Jan Schultke Eisenwave

View GitHub Profile
@Eisenwave
Eisenwave / pointers.md
Last active October 23, 2024 20:43
How pointers in C++ actually work

How pointers in C++ actually work

Abstract: This document teaches you from the very basics to advanced features such as std::launder how pointers in C++ work. It is aimed at developers of any skill level. However, it links to the C++ standard so that advanced readers can verify the information and investigate further.

Motivation: Most tutorials on pointers are aimed at beginners, and present a simplified model. Some tutorials perpetuate an explanation of pointers that is solely based on their implementation (pointer = memory address). This tutorial aims to provide a comprehensive explanation of pointers that is in line with how they actually work from a language perspective.

@Eisenwave
Eisenwave / case_against_almost_always_auto.md
Last active September 19, 2024 16:53
The case against Almost Always `auto` (AAA)

The case against Almost Always auto (AAA)

Introduction

I've been writing C++ for half a decade now, and auto has always been a great source of discomfort to me. Whenever I came back to a past project that makes extensive use of it, I found myself confused, and first had to look at all the types before I could make sense of it.

Similarly, I've worked as an intern at a company that had a AAA policy for its code base. Whenever something didn't work, and I had to debug some code, half the time was spent just looking up types.

@jeremy-rifkin
jeremy-rifkin / malloc.hpp
Last active April 6, 2022 12:37
High performance malloc implementation
uintptr_t base;
const uintptr_t height = 100000000;
std::mt19937 rng;
[[gnu::constructor]] void init_malloc() {
base = (uintptr_t) sbrk(height);
}
void* malloc(size_t) { // parameter ignored, we don't need it
return (void*)(base + rng() % height); // odds of any collision is like, low
}
void free(void*) {} // no-op
@msikma
msikma / rfc5646-language-tags.js
Created February 26, 2015 13:51
RFC 5646 Language Tags
// List of language tags according to RFC 5646.
// See <http://tools.ietf.org/html/rfc5646> for info on how to parse
// these language tags. Some duplicates have been removed.
var RFC5646_LANGUAGE_TAGS = {
'af': 'Afrikaans',
'af-ZA': 'Afrikaans (South Africa)',
'ar': 'Arabic',
'ar-AE': 'Arabic (U.A.E.)',
'ar-BH': 'Arabic (Bahrain)',
'ar-DZ': 'Arabic (Algeria)',