|
Edgy techniques used in
þ are called tricks on this page because I
don't entirely approve even though I do them anyway.
string alignment
To start this page (so it's not empty) first consider the following define assuming something about static C strings: #define example_TAG (*(uint32_t*) "exmp")
This casts a pointer to a C string to a pointer to a 32-bit integer and dereferences it. I put these in code as rhs (right-hand-side) expressions read when initializing something else or comparing for equality. I like magic signatures in objects to look human readable when memory is hexdumped, and this is simpler than working out a hex integer constant in local endianess. But to an old school view (which I have) this is really creepy: it assumes address alignment will be okay, and assumes how physical representation of strings work in C and C++ runtimes. Assumptions are often bad — portable would be better. But a pragmatic view says: if it doesn't work, change it later; what's the big deal? Wil usually assumes an Intel architecture processor which happily reads and writes memory at any alignment, simply going slower for non-aligned locations. So Wil seeks alignment for speed but doesn't sweat a few cases when alignment is missing. |
menu
thorn: todo, names, fd, iovec, assert, log, run, hex, crc, buf, in, out, quote, escape, compare, file, deck, cow, arc, blob, tree, slice, rand, time, stat, hash, heap, node, primes, page, book, pile, stack, atomic, lock, mutex, thread, map, meter, list, iter, ctype (mu: toy, peg, imm, tag, box, symbol, token, number, bigint, class, method, reader, writer, eval, env, vm, gc, world, pcode, compiler, asm, lathe, lisp, smalltalk, design, weight, jar, card, harp, debug, profile) Some demos are stubs: todo is a demo guide. See toy for mu updates on language pages; names introduces naming schemes. Content for tricks will accumulate slowly as specific issues to be described come to mind. Their numbers should not be so great more than one page is needed.
unportable
Some "tricks" are just non-portable mechanisms. Wil doesn't worry about how to write code so it works anywhere and everywhere it's compiled — not without a requirement for that. Wil generally works on Unix-based platforms (Linux and MacOS) so he freely relies on mechanisms found there. When they appear in demos, this fact might only be noted. Wil won't write a general API that can be subclassed differently so it works on all platforms. That's too much like work, and you don't pay. Just imagine Dex and Wil exchange taunts often: "That's not portable!" quips Dex. "Duh!" retorts Wil. |