Homebrew code.
> Is it possible for anyone to write 3DS code, compile it with GCC + friends, and run it on an off-the-shelf 3DS?
Yes. You need a flash cart for this. GBA Temp has a nice sub forum for this: http://gbatemp.net/forums/3ds-hacking-homebrew.201/
IIRC, some of the flashcarts have an Emunand feature that lets you play games requiring a newer version (i.e, 6.x) on a 3DS without updating your firmware from 4.x (4.x is required to support the current crop of flashcarts)
I couldn't find much, but it seems that a team called "Gateway" found a userland+kernel exploit that allowed everyone to run unsigned code on the 3DS. It got fixed a bunch of updates ago.
As for how, it seems that the documentation is very bad/completely missing, but from what I get you can write C, compile it with GCC for arm (https://launchpad.net/gcc-arm-embedded) and pass it with some tools to allow booting from the exploit. To interact with the hardware (eg draw to the screen) it seems you can just manipulate directly memory (see https://github.com/Aliakr18/mandelbrot/blob/master/source/me...)