Skip to content

Instantly share code, notes, and snippets.

Nicolas uucidl

Block or report user

Report or block uucidl

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.

View gui.c
/* ===========================================================================
* =========================================================================== */
/* Proof of Concept GUI:
* - PoC UI implementation in ~2.5kLOC of C89 (ANSI C)
* => Core solutions has no external dependencies (removing standard library dependency is trival)
* => Does not use or require any special language constructs or macro constructs just pointers and enums
* - Combines both "retained" and "immediate mode" UI by providing control over update frequency
bryanedds / PlatonicSolidsOfSoftwareConstruction.txt
Last active Dec 12, 2017
The Platonic Solids of Software Construction and Their Realization in C
View PlatonicSolidsOfSoftwareConstruction.txt
No matter the business domain or programming language, programmers always end up needing support for ALL of these things
in some form -
* Resource Semantics (such as RAII in C++, or finalizers in C#)
* Error Semantics (such as exceptions in most languages, or conditions in Common Lisp)
* Algebraic Types (such as structs and unions in C, or records and DUs in F#)
* Data Abstraction (such as that which is often badly entangled within object systems in OO languages)

Graphical User Interfaces

For the last few weeks I spend some time coding, writing and cleaning up my notes from almost a year since I published nuklear.

Basically this is a possible implementation for a graphical user interface builder backend with support for an immediate mode style API. So it provides a way to define non-mutating UI state, an immediate mode style API for dynamic UI components (lists,trees,...) and a combination of both.

The core implementation is ~800 LOC without any kind of default widgets or extensions. At first this seems quite counter intuitive. However since the inherent design allows for lots of different ways to define any widget like buttons it does not make sense to provide a specific default implementation. The way this code was architectured furthermore removes the need for style/skinning configurations used in Nuklear since widget painting is just calling a small

rygorous / box_pruning_notes.txt
Created Feb 17, 2017
Note on changes to the box pruning code.
View box_pruning_notes.txt
Brief explanation what I did to get the speed-up, and the thought process behind it.
The original code went:
movaps xmm3, xmmword ptr [edx+ecx*2] // Box1YZ
cmpnltps xmm3, xmm2
movmskps eax, xmm3
cmp eax, 0Ch
View Pimpl.cpp
struct Data
View task_api.txt
typedef int task_t; // Lower bits as table index, upper bits as generation counter for use-after-free detection.
typedef void (*task_function_t)(void *task_data);
task_t task_create(task_function_t task_function, void *task_data);
void task_depends(task_t task, task_t dependency);
void task_start(task_t task);
Upon completion, tasks signal their dependencies and are released.
Memory requirements for a minimal implementation: 16/24 bytes per task and 8 bytes per dependency edge.
Even so, you still don't want to have one task instance for every array entry in a gigabyte array. Always assign
View offset_hack.c
typedef union {
struct { char pad_x[31]; int x; } __attribute__((packed));
struct { char pad_y[512]; int y; } __attribute__((packed));
// ...
} __attribute__((packed)) overlay;
// Macrofied:
#define JOIN1(x, y) x##y
#define JOIN(x, y) JOIN1(x, y)
View vex.txt
Vex is a minimalistic markup language with the motto "form without meaning".
This is going to @italic=really hurt.
// @author: Per Vognsen
// @version: 1.3
The weather forecast for @date is @weather.
View compiling_logical_expressions.txt
Suppose you are writing a simple one-pass compiler in the Wirth style, and you want to
target non-RISC architectures like the x86 where conditional operations use shared condition state.
Case 1:
if (x <= y) z = w
CMP x, y
JGT skip
MOV z, w
You can’t perform that action at this time.