Skip to content

Instantly share code, notes, and snippets.

@mcjohnalds
mcjohnalds / how-to-report-errors-in-c.md
Created May 12, 2016 12:28
How to report errors in C.

How to report errors in C

C doesn't support exceptions, but we can store error messages in structs. This document compares 3 different strategies of error reporting.

typedef enum {
    FILE_NOT_FOUND_ERROR,
    INVALID_FILE_FORMAT_ERROR,
    ...
@mcjohnalds
mcjohnalds / how-to-do-error-reporting-in-glib.md
Created May 12, 2016 12:25
Here's how to do error reporting in GLib

How to do error reporting in GLib

C doesn't support exceptions but GLib has its own error reporting system. It's kind of verbose but it works ok.

Let's pretend we were making a JSON parser library, here's how the error reporting would work. (This example was actually derived from json-glib).

First we create an enum to represent different error codes.

@mcjohnalds
mcjohnalds / kochsnowflake.html
Last active December 27, 2020 00:16
A Koch snowflake. Uses WebGL for no particular reason. Doesn't use any trig b.c trig is lame.
<script id="shader-vs" type="x-shader/x-vertex">
attribute vec2 aPosition;
void main(void) {
gl_Position = vec4(aPosition, 0.0, 1.0);
}
</script>
<script id="shader-fs" type="x-shader/x-fragment">
void main(void) {