Break it real good

Curtis Bartley has a fantastic post up describing his use and abuse of the C++ preprocessor:

A few months back I got this wild idea that you could insert trace-logging code (not jit-tracing, that's something else) into more or less arbitrary C++ by redefining certain C++ keywords as macros.
He goes on to describe how he redefines if, for, switch, and do.  In the process he uses the highly useful FILE and LINE macros.  I love this.  All of my work on DXR to extract every last drop of semantic info from the Mozilla source and build relies on shenanigans just like this.  I've had to use, abuse, rewrite, and hack our build system, preprocessor, xpidl, JS preprocessor, C++ code, etc.  You can't be afraid to bend your tools in order to have them fit new uses.  Open tools and source code aren't just open to study and improvement; they are also open to new uses and re-imagined purposes.

I for one hadn't thought to do what he's done here, and I plan on keeping the idea in my back pocket as I continue my work to add more data to DXR.  Thanks, Curtis!

UPDATE: apologies to Curtis for calling him Chris, corrected.

Show Comments