Skip to content

Instantly share code, notes, and snippets.

@Ravenstine
Created September 10, 2016 15:17
Show Gist options
  • Save Ravenstine/ab3c177dc2a7068de4662255670c19f4 to your computer and use it in GitHub Desktop.
Save Ravenstine/ab3c177dc2a7068de4662255670c19f4 to your computer and use it in GitHub Desktop.
Super Function in C
// This isn't exactly like having super-methods, especially since there are no
// classes or inheritances in C, but this can be useful with things like LD_PRELOAD
// where you want to override or proxy an existing function, and want the function
// to continue executing as it usually would(vs being a no-op).
#define _GNU_SOURCE
#include <dlfcn.h>
void glVertex3f(float x, float y, float z){ // an OpenGL function
static void (*super)(float, float, float) = NULL;
if (!super)
super = (void(*)(float, float, float)) dlsym(RTLD_NEXT, "glVertex3f");
super(x, y, z);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment