Skip to content

Instantly share code, notes, and snippets.


John Bartholomew johnbartholomew

View GitHub Profile
johnbartholomew / no-init-list.cpp
Created Jan 21, 2014
Testing nested initializer-lists without initializer-list constructors.
View no-init-list.cpp
/* Compiles and works with recent GCC and Clang in C++11 mode.
* $ g++ --version
* g++ (GCC) 4.8.2 20131219 (prerelease)
* $ clang++ --version
* clang version 3.4 (tags/RELEASE_34/final)
#include <vector>
#include <iostream>
johnbartholomew /
Last active Jan 2, 2016
bad regex! no cookie!
View nfa-example-1.c
#include "nfa.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void) {
Nfa *nfa;
NfaBuilder builder;
View test-mkstemp.c
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
static const char MESSAGE[] = "Hello, world!\n";
int main(void) {
char fname[64];
int fd;

I'm not trying to precisely match the behaviour of an existing glob syntax unless that behaviour really seems like the most obvious/easiest-to-use syntax. However, I do want globs to feel familiar to use.

I'll say that '**' matches anything, and '*' matches anything except directory separators. Without thinking too hard, how do you expect the following globs to behave?

  1. *.c
  2. **.c
  3. **/*.c
View test.c
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
static void check_access(const char *path) {
int ret = access(path, F_OK);
if (ret == -1) {
int e = errno;
printf("access '%s' failed: %s\n", path, strerror(e));

Some definitions:

  • A "safe" transformation is a transformation of a path A into a path B such that any file system operation on path A will produce the same behaviour if given path B.

  • "normalize" means remove redundant directory separators (including trailing separators) and replace non-canonical separators with canonical separators (on Windows, backslash is the canonical separator, but forward slashes are also recognised as separators. On POSIX, forward slash is the only separator character and is canonical). Normalization is trivially "safe"; it doesn't add or remove any path components,

johnbartholomew / gist:6811245
Last active Dec 24, 2015
Creating statically linkable C "packages"
View gist:6811245
#define PACKAGE_PRIVATE __attribute__((__visibility__("hidden")))
#define PACKAGE_PUBLIC __attribute__((__visibility__("default")))
/* -------- a.c -------- */
static int the_thing = 42;
PACKAGE_PRIVATE int compute_thing(void) {
return the_thing;
View text.glsl
// ---- text.vert.glsl
#version 150
uniform vec2 text_offset;
uniform vec2 rcp_screen_size;
in vec2 v_screen_pos;
in vec2 v_uv;
out vec2 f_uv;
johnbartholomew / ClangWarnGlobals.cpp
Created May 28, 2013
A Clang plugin to generate warnings for non-const global variables.
View ClangWarnGlobals.cpp
// -Wglobals Clang plugin
// Based on example plugins and searching Clang's API documentation.
// BEWARE! This is my first ever attempt at a Clang plugin.
// Makefile
#if 0 WarnGlobals.cpp
clang++ -std=c++98 -shared -fPIC $$(llvm-config --cflags --libs support mc) -o "$@" $^ -L/usr/lib/llvm/ -lclang