Skip to content

Instantly share code, notes, and snippets.

Joe Savage joesavage

Block or report user

Report or block joesavage

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile

Multi-dimensional array views for systems programmers

As C programmers, most of us think of pointer arithmetic for multi-dimensional arrays in a nested way:

The address for a 1-dimensional array is base + x. The address for a 2-dimensional array is base + x + y*x_size for row-major layout and base + y + x*y_size for column-major layout. The address for a 3-dimensional array is base + x + (y + z*y_size)*x_size for row-column-major layout. And so on.


FWIW: I didn't produce the content presented here (the outline from Edmond Lau's book). I've just copy-pasted it from somewhere over the Internet, but I cannot remember what exactly the original source is. I was also not able to find the author's name, so I cannot give him/her the proper credits.

Effective Engineer - Notes

What's an Effective Engineer?

View gist:8c909975de4bb071056b4ec1651077e8
/* ========================================================================
$File: tools/ctime/ctime.c $
$Date: 2016/05/08 04:16:55PM $
$Revision: 7 $
$Creator: Casey Muratori $
The author of this software MAKES NO WARRANTY as to the RELIABILITY,
rygorous / gist:e0f055bfb74e3d5f0af20690759de5a7
Created May 8, 2016
A bit of background on compilers exploiting signed overflow
View gist:e0f055bfb74e3d5f0af20690759de5a7
Why do compilers even bother with exploiting undefinedness signed overflow? And what are those
mysterious cases where it helps?
A lot of people (myself included) are against transforms that aggressively exploit undefined behavior, but
I think it's useful to know what compiler writers are accomplishing by this.
TL;DR: C doesn't work very well if int!=register width, but (for backwards compat) int is 32-bit on all
major 64-bit targets, and this causes quite hairy problems for code generation and optimization in some
fairly common cases. The signed overflow UB exploitation is an attempt to work around this.

Orthodox C++

What is Orthodox C++?

Orthodox C++ (sometimes referred as C+) is minimal subset of C++ that improves C, but avoids all unnecessary things from so called Modern C++. It's exactly opposite of what Modern C++ suppose to be.

Why not Modern C++?

rygorous / gist:c6831e60f5366569d2e9
Last active Oct 13, 2016
Please tell me more about your "zero-cost abstractions".
View gist:c6831e60f5366569d2e9
// Conjugate split-radix FFT inner loop
// Both of these compiled with VC++ 2012, 32-bit, "/O2 /fp:fast".
// NOTE: I also tried clang-cl and it seems to be primarily a VC++
// problem. (Which doesn't help me much.)
// NOTE 2: argh, did the Clang test wrong. It's still primarily a
// VC++ problem, but Clang has a notable slowdown too. Anyway, new
// results generated automatically from a simpler standalone test
// where I can toggle between versions using a single commandline
joesavage / brainfuck.cpp
Created Nov 17, 2014
Brainfuck Compiler/Interpreter
View brainfuck.cpp
// A small, and relatively primitive, C-style Brainfuck compiler/interpreter.
// Written by Joe Savage, 2014
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <limits.h>
#define STACK_SIZE 512
#define DATA_SIZE 65535
aras-p / preprocessor_fun.h
Last active Feb 17, 2020
Things to commit just before leaving your job
View preprocessor_fun.h
// Just before switching jobs:
// Add one of these.
// Preferably into the same commit where you do a large merge.
// This started as a tweet with a joke of "C++ pro-tip: #define private public",
// and then it quickly escalated into more and more evil suggestions.
// I've tried to capture interesting suggestions here.
// Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_,
// @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant,
You can’t perform that action at this time.