Productivity Boost – Note and Warn Macros

Thanks to a guy named Patrick Wyatt and his nifty open source base C++ project, I’ve learned a couple new tricks. The one I’d like to share in this post is a great productivity booster. I myself am a very forgetful person, and need to constantly write myself notes in order to remember anything. Wouldn’t it be great to somehow leave notes within your code, in order to remember things? The most common note I leave looks something like this:

This way I can use ctrl + f to cycle through all of my todos that I’ve left laying around in my code. The only problem is that sometimes I forget for days and days to use ctrl + f, thus cutting into my productivity. This is particularly bad, because if I can’t remember where I need to start working once I open my solution, then I have to spend a very long time getting up and running again. If I do however remember what I’m supposed to start on, then I happily get back to work immediately. I just need that simple todo list so know what’s going on.

Within Visual Studio you can output some text through the compiler with a small pragma preprocessor directive:

This can be modified a little bit to make use of visual studio formatting, to allow a user to double click on a message from the compiler and then jump to that specific line of code:

So now whenever we need to add a note or warning, or anything during compilation we can copy paste this line and modify the Some message portion. This is pretty annoying. Visual studio has a nifty __pragma operator that can be placed within a macro like so (since we can’t place a #pragma within a macro):

And now with use of the__pragma operator we have a wonderful macro to toy around with. It can be double clicked on, and the cursor will jump to the line that this macro was placed within your code. The only part left to explain is the STRINGIZE macro. It just takes input and stringizes it with the # operator. A quick google search should explain the next code segment:

Now that the tools needed for nifty WARN and NOTE macros are available, here’s my finalized macros:

These macros are awesome and have saved me tons of time. They also look quite clean during use and can be placed pretty much anywhere you’d like within your code. It might be a bit hectic to use prolifically in large projects, but for smaller isolated compilations like unit tests, these things rock.

Here’s some output from a project I’m currently working on:

Click to Show SelectShow

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">