Skip to content

Instantly share code, notes, and snippets.

template<typename T, size_t N>
T* end_of(T (&arr)[N])
{
return &arr[0]+N;
}
// ...
int arr[42];
std::fill(arr, end_of(arr), 25);
# polymorphism in bash ?
prepare_c() {
cp ~/c_skeleton $1
cp ~/c_makefile_skeleton $1
}
prepare_bash() {
cp ~/bash_skeleton $1
}
@wilhelmtell
wilhelmtell / gist:347445
Created March 29, 2010 05:10
Dynamically load and invoke a function in C++
///////////////////////////////////////////////////////////////////////////////
// dyn.cc - compiled and linked as a dynamic library
///////////////////////////////////////////////////////////////////////////////
#include <iostream>
extern "C" void fun()
{
std::cout << "BOOYA!!1! fun() invoked!\n";
}
#include<stdlib.h>
#include<stdio.h>
typedef struct state_t {
int current_line;
int heading_level;
token* previous_token;
} state;
state* state_with(state* s) /* just for readability when invoking */