andersch.dev

Articles

<2024-05-31>
[ cpp c ]

Embedding Binaries in C(++)

Five ways to bake any file as a buffer into your executable

When programming, it can be desirable to embed the data of arbitrary binary files directly in the final executable of your application. This is great to:

Here is a list of some of the ways you can achieve this (comfortably) in C and C++.


<2024-05-29>

#include "shader.glsl"

How to leverage the C preprocessor to write reusable, hot-reloadable shader code

OpenGL tutorials usually skip over any file I/O code by telling you to write out your very first shader as a string literal like this:

const char* vertex_shader_source = "#version 330 core\n"
    "layout(location = 0) in vec3 aPos;\n"
    "void main() {\n"
    "    gl_Position = vec4(aPos, 1.0);\n"
    "}\0";

// ...or using raw string literals (>C++11):
const char* fragment_shader_source = R"(#version 330 core
    layout(location = 0) in vec3 aPos;
    /* ... */)";

This becomes impractical for more complex shaders, since it's tedious to write and we lose any syntax highlighting. Here is an alternative approach that still avoids file I/O and has some additional advantages.


<2020-11-20>
[ lisp ]

The Lisp Programming Language and its Influence

A paper on the history, influence and concepts of the Lisp family of programming languages

As part of a university seminar on programming languages I wrote a small paper on Lisp. It ended up being about the history of Lisp and its dialects, their influences on other languages, as well as a short tutorial on how Lisp works.