A little stack machine

Threw this together to show an example of computed goto. Computed goto is a handy tool for building little interpreters. #include #define NEXT goto **ip++ int main() { int fact = 6, fact_b0 = 16; void* program[] = { &&push, (void*)5, &&call, (void*)fact, &&printi, &&end, &&beq0, (void*)fact_b0, &&dup, &&push, (void*)1, &&sub, &&call, (void*)fact, &&mult, &&ret, […]

Concepts: Typeclasses for C++?

I’ve had a hypothesis for a while that C++ templates (paired at times with ADL) are an ad-hoc, unsound version of typeclasses. I’ve seen this hold for parser combinators, range base algorithms, and more. I’m also not the first to draw this comparison[1]. Concepts are supposed to bring soundness in through constrained templates. Concepts look awfully […]

The case of the different shifts

Larry Osterman has commented on an interesting edge case in the C/C++ standards, involving the underflow of the right shift operator. They reported that if they compiled code which calculated: 1130149156 >> -05701653 it generated different results on 32bit and 64bit operating systems. On 32bit machines it reported 0 but on 64bit machines, it reported […]

Comma Abuse

Found this old C++ source file in my scratch directory, apparently from last September. I don’t even remember writing this, but it’s written using my idioms. If I did write it, rest assured it was primarily for amusement purposes (abusement purposes?) only. #include <iostream> using namespace std; int fibonacci(int x) { int a=0, b=1, temp; while(x?(–x,temp=a,a=b,b=temp+b):0); return […]

Native Client at UWCS lecture

Available for streaming and download, Google Native Client presented at UW’s computer science lecture series. Covers the restrictions on x86 code, new alignment rules, and performance on various benchmarks. 5% overhead, that’s nothing compared to many other sandboxing techniques. Native client is 50KB download?  Wild. It really is just a gatekeeper, runtime library separate. Of […]

Memoizer, in C++

Part of what I’m trying to do here is record experiments, little bits of code demonstrating software techniques.  This is a revisit of a recent one. As a refresher, memoization is a dynamic programming technique used to optimize the time to solve problems where partial problems overlap frequently.  For example, in the recursive definition of […]