C++ resources and a rearrangement of learncpp.com
- cppreference (C/C++ Documentation)
- Compiler Explorer (Running and sharing code)
- Coliru (Somewhat similar)
- C++ Standard Working Draft
| /* | |
| * gcc -O2 -march=native -mtune=native -flto=auto rounding.c -o rounding -lm | |
| */ | |
| #define _GNU_SOURCE | |
| #include <ctype.h> | |
| #include <errno.h> | |
| #include <fenv.h> | |
| #include <math.h> | |
| #include <stdio.h> | |
| #include <stdlib.h> |
| /* Whether you want to catch bugs in production | |
| * or just want to help hackers interface with | |
| * your program, sometimes it's nice to have | |
| * your binary explain what it's doing in a | |
| * human-readable way. Audit trails are just | |
| * no-op functions that help you document your | |
| * binary for the sake of future debuggers. | |
| * in gdb: | |
| * b audit_trail | |
| * commands |
| /** | |
| * Atomics & threads complement library | |
| * Matthew Reiner, 2026 | |
| * Available under the MIT license | |
| * Targeting: Windows, Linux, FreeBSD, NetBSD, OpenBSD, MacOS | |
| * Implements the following: | |
| * - Wait/Notify functionality for simple types up to 64 bit | |
| * - Arbitrary condition wait | |
| * - Fine-grained memory ordering | |
| * - Thread management |
| // Not sure this can be copyrighted, but if so: | |
| // (c) m1lkweed, 2026, licensed under cc0 where required | |
| // Dedicated to the public domain | |
| typeof(const char[5]) pixels[256] = { | |
| "⠀", "", "", "🮂", "", "▘", "", "", "", "", "▝", "", "", "", "", "▀", | |
| "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", | |
| "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", | |
| "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "🮅", | |
| "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", | |
| "▖", "", "", "", "", "▌", "", "", "", "", "▞", "", "", "", "", "▛", |
| #include "list.h" | |
| List list_instance(size_t type_size) { | |
| return (List){ | |
| .data = malloc(0), | |
| .size = 0, | |
| .type_size = type_size | |
| }; | |
| } |
| #include <stdio.h> | |
| #define py_for(...) _Pragma("GCC diagnostic push")_Pragma("GCC diagnostic ignored \"-Wdangling-else\"") \ | |
| for(struct{int count; bool broke; bool once; bool copy;}py_for = {}; \ | |
| (py_for.count < 2) && !py_for.broke; ++py_for.count)if(!py_for.count)for(__VA_ARGS__) \ | |
| if(py_for.broke){break;}else for(py_for.once = true; (py_for.copy = py_for.broke), \ | |
| (py_for.broke = py_for.once), py_for.once && !py_for.copy; py_for.broke = py_for.once = false) \ | |
| _Pragma("GCC diagnostic pop") | |
| #define py_whl(...) py_for(;__VA_ARGS__;) |
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.
| // Compares types of both parameters. Returns true if the types are compatible, otherwise false. | |
| // Parameter y may not be a variably-modified type. | |
| // Designed to be a drop-in replacement for gcc's __builtin_types_compatible_p | |
| #define types_compatible_p(x, y) _Generic(((typeof_unqual(x)*){}), typeof_unqual(y)*:1, default:0) | |
| // Cast the bits of arg to type. Parameter type must be a type and must not be a literal or object with that type. | |
| // Designed to be compatible with g++'s __builtin_bit_cast | |
| #define bit_cast(type, ...) ( \ | |
| union{typeof(__VA_ARGS__) in; typeof(type) out; \ | |
| int enforce_type:_Generic((int(*)(int(type)))0, \ |
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.