Custom Comment-Out Macro | CodeGuru

Custom Comment-Out Macro

I think that sometimes commenting source code can be cause of great mess if we don’t write WHY we are commenting it and, for istance, whether it is a temporary action or it is supposed to be definitive. This is particularly true when you work in team and you dare to hope to understand what […]

Written By
CodeGuru Staff
CodeGuru Staff
Aug 2, 2000
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

I think that sometimes commenting source code can be cause of great mess if
we don’t write WHY we are commenting
it and, for istance, whether it is a temporary action or it is supposed to
be definitive. This is particularly
true when you work in team and you dare to hope to understand what is
happening around you (no hopes! 😉 ).

For this reason it can be useful to insert comments like this

// Commented by Ilic On 31/7/00   CString Message;
// Commented by Ilic On 31/7/00   Message.Format(_T("Useless message"));

or this

// Moved to AnotherLibray	MyClass *Ptr;
// Moved to AnotherLibray	Ptr->SolveAllMyProblems();

This is possible with the included Macro. Comment is divided in three
parts:

  1. the CommentType (//, ‘, # and so on), which was already beautifully
    mastered by Adam Solesby.
  2. The Comment itself, i.e. the sentence you want to be written near your
    commented code.
  3. The comment delimiter, which separates your sentence from the code. It is
    set by default as a vTab, but you can change it to whatever you want,obtaining e.g.
    // Moved to AnotherLibray --> MyClass *Ptr;
    // Moved to AnotherLibray --> Ptr->SolveAllMyProblems();
    

The ChangeCustomComment() macro allows you to change the sentence you want
to put in next comment, whereas
InsertCustomComment() is simply the extension of Adam Solesby’s macro. You
can change your comments as many
times as you want, and you should always be able to Uncomment code, no
matter whether the sentence in the comment
you want to delete is the same of the “active” one or not. On the countrary
you shouldn’t change the comment
delimiter once you have chosen one, or the macro want be able to recognize
comments anymore (nobody’s perfect…)

Downloads

Download source – 3 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.