## Pages

### Weinberg on writing

is an excellent book edited by Jerry Weinberg (isbn 0-932633-65-X). As usual I'm going to quote from a few pages:
Writer's block is not a disorder in you, the writer. It's a deficiency in your writing methods - the mythology you've swallowed about how works get written - what my friend and sometime coauthor Tom Gilb called your "mythology".
It's not the number of ideas that blocks you, it's your reaction to the number of ideas.
A trigger is a small amount of input energy that sets off a large amount of output energy.
"You know, there would be no problem raising kids if only you could throw away the first one."
The essence of the Fieldstone Method is to gather great quantities of words and then to discard a slightly less great quantity.
Learning, it seems, is a matter of repeated attempts, until one finds a teacher, a book, a film, an approach, a flash, or something that finally gets the point across.
About one third of the time, the problem turns out to be that the passage didn't mean anything, or meant several things at once.
Mozart used dice to produce ideas for musical themes, and even designed a dice game for composing new minuets.
Often, in the middle of a game, an idea will pop into my mind, and I will immediately pop it into the window I have open for the manuscript. Sometimes, I continue writing from that idea for hours. When I finish, I'm generally surprised to find a half-finished solitaire game in progress.

### C macro magic - PP_NARG

I've just spent two days delivering my C Foundation course to the massively talented people at Cisco (nee Tandberg nee Codian) in Langley. One of the guys on the course called Alex showed me an amazing C99 macro that counts the number of parameters. The capacity of C to surprise me with something new never ceases to amaze. Here it is (cut down to handle just 6 parameters to save space):
```#include <stdio.h>

#define PP_NARG(...) \
PP_NARG_(__VA_ARGS__, PP_RSEQ_N())

#define PP_NARG_(...) \
PP_ARG_N(__VA_ARGS__)

#define PP_ARG_N( \
_1, _2, _3, _4, _5, _6, N, ...)   (N)

#define PP_RSEQ_N() \
6,5,4,3,2,1,0

int main(void)
{
printf("%d\n", PP_NARG(a,b+c+d)); // 2
printf("%d\n", PP_NARG(a,b,c,d,e+f)); // 5
return 0;
}
```
Alex mentioned it doesn't work for zero parameters - it incorrectly returns one. Of course I can't resist seeing if I can fix that. After playing around a bit I've come up with this which seems to work.
```#define PP_NARG(...) \
PP_NARG_(sizeof #__VA_ARGS__, __VA_ARGS__, PP_RSEQ_N())

#define PP_NARG_(delta, ...) \
PP_ARG_N(delta, __VA_ARGS__)

#define PP_ARG_N( \
delta, _1, _2, _3, _4, _5, _6, N, ...)   (N - ((delta)==1))

#define PP_RSEQ_N() \
6,5,4,3,2,1,0
```
Alex joked that at parties he's tried to impress girls with this macro. Of course he increases the number of parameters to 128. Size matters after all. And naturally he boasts not only of the macro's size but also of it capacity for expansion!