Revision e59c051f-d2b5-4064-bd41-3e8ebef3cfa0 - Code Golf Stack Exchange

Use *cursors* instead of pointers. Snag the `brk()` at the beginning and use it as a *base-pointer*.

 char*m=brk();

Then make a #define for memory access.

 #define M [m]

`M` becomes a postfix `*` applied to integers. (The old a[x] == x[a] trick.)

But, there's more! Then you can have pointer args and returns in functions that are shorter than macros (especially if you abbreviate 'return'):

 f(x){return x M;} //implicit ints, but they work like pointers
 #define f(x) (x M)

To make a cursor from a pointer, you subtract the base-pointer, yielding a ptrdiff_t, which truncates into an int, losses is yer biz.

 char *p = sbrk(sizeof(whatever)) - m;
 strcpy(m+p, "hello world");

This technique is used in my answer to http://codegolf.stackexchange.com/questions/284/write-an-interpreter-for-the-untyped-lambda-calculus/3290#3290.

AltStyle によって変換されたページ (->オリジナル) /