Some (more) things I either learned fresh or happened to talk with friends about today! Details below the fold.
assertis for saying what you want!allocais special- I had a linguistic race condition
assert is for saying what you want!
The condition passed to C's assert macro should say what you want to be true, not what you don't want to be true. It sounds simple and obvious, but given how rarely C/C++ rarely are simple and obvious, it's incredibly easy to second-guess yourself...
alloca is special
The C function alloca is (probably) not actually a function, in the sense of "a thing that gets called at the assembly level". Since the bounds of the current stack frame is just "that stretch of memory between the stack address and the frame address", you can just bump the stack pointer by a few bytes et voila, a new variable has appeared.
True functions participate in a calling convention, which describes which registers get saved to the stack by the caller (leaving them free for use by the callee) and which registers the callee must take care not to stomp on. If alloca were a function, it would have to not only adjust the previous frame's stack pointer, but also make sure that it shifted all of the registers the caller saved so that they'd still be in the same relative place when the caller returns (and expects to load them back).
It's very bad juju to mess with stack data outside your own frame, so while it could be done this way, compilers (and regular developers!) are probably much happier just letting alloca be a special built-in that resolves to a simple one-instruction stack pointer bump.
(Actually, a hell of a lot of standard library functions get some amount of special treatment, and IIRC the compiler is explicitly allowed to assume that e.g. a use of printf will always be linked with the standard library printf. I don't remember where I saw this, so don't quote me on that specific example; the point I'm making is that C is a language with a lot of special cases.)
Linguistic race conditions
I was talking to a friend today, and I made the following utterance:
"[...] In the new way things that we have them [...]"
This... is grammatical nonsense. I'm pretty sure I meant to say "In the new way we that we have things", but obviously some wires got crossed. I think two things happened here:
- I said "things" too early. Just a permutation error, nothing else to it.
- I said "them" instead of "things". This is weird! I recognized that I'd said "things" earlier, but instead of just not saying it here, I referred back to that "things" with a pronoun.
Of course, none of this was conscious! This is me just trying to explain what caused that to happen. I was just trying to say a thought, and somehow the thought-to-speech serialization machine in my head stumbled and caught itself. Weird!