Pascal Strings with the C Preprocessor

Just a random cool thing you can do:

#define PASCAL_STRING(s) \
    (((struct { uint8_t n; char buf[sizeof(s)-1], flag[-(sizeof(s)>256)]; }) \
        { sizeof(s)-1, s }).buf)

The reason I came up with this is that I wrote a die procedure that writes a static string to stderr and exits. With standard C strings it needs to call strlen or use rep scasb, but with Pascal strings it's just load length and syscall. Neat.

The flag is a standard trick for static_assert.