4 ms·
It's called a jump table or vtable. It's one of the examples in Forth. Plan 9 uses that technique in C a lot too. This example is ramfs which creates an in me
by SixSigma 12y ago
It's called a jump table or vtable.
It's one of the examples in Forth. Plan 9 uses that technique in C a lot too.
This example is ramfs which creates an in memory file system (that you can mount in Unix btw, in 166 LoC)
http://swtch.com/usr/local/plan9/src/lib9p/ramfs.c http://swtch.com/usr/local/plan9/src/lib9p/ramfs.c
fsopen, fsread, fswrite, fscreate are C functions declared in the same source file :
Srv fs = {
.open= fsopen,
.read= fsread,
.write= fswrite,
.create= fscreate,
};
fs is then passed to a library which calls them as needed.