In which Pooh understands the C preprocessor

Christopher Bazley, August 2013

While walking in the hundred acre wood, Pooh, Piglet and their friend Rabbit came across a fragment of a C source file:

#define STRINGIFY( x ) #x
#define STRINGIFY2( x ) STRINGIFY( x )
#define LOCATION __FILE__ ":" STRINGIFY2( __LINE__ )

Piglet wondered to himself why STRINGIFY2 was needed. "You may well wonder, young Piglet!" said Rabbit grandly. "That is woozle magic passed down from your grandfather Trespassers William." He added sternly that one shouldn't enquire further as woozles were subtle and quick to anger.

Pooh, although a bear of little brain, could not help thinking about the woozles. "Piglet", he whispered. "Do you think perhaps __LINE__ is not expanded if used as an argument to a macro with # in the definition?" Piglet wasn't sure, but thought Owl might have a copy of The C Programming Language in his library.

Owl invited them in for a little something. Piglet squeezed Pooh's paw by way of encouragement, and Pooh humbly told Owl the thing that he had thought, which had seemed very thingish until it got out in the open with everyone looking at it.

Owl cleared his throat noisily, then said that Pooh had thought a Very Clever Thing because arguments are not macro-expanded during collection, nor before insertion if an occurrence of a parameter in the replacement sequence is immediately preceded by #.

Pooh felt very proud. "Do you think it is because Rabbit is so clever that he never understands anything?" asked Piglet. Eeyore, who had dropped in to enquire whether Owl's house had blown down lately, opined that the woozle magic probably wouldn't work anyway because the compiler mightn't be standards compliant. However, Pooh decided not to worry any more about the woozles because he could hear his pots of honey calling him.