Click here to Skip to main content
15,867,686 members
Articles / Programming Languages / C++

FIXME - A Smart FIXME Macro

Rate me:
Please Sign up or sign in to vote.
5.00/5 (28 votes)
25 May 2009CPOL 55.5K   33   30
Using this smart 'FIXME' macro will help you not to forget to fix your code.

Introduction

If you are using Visual Studio, this FIXME macro will help you not to forget to fix your code before you release it. During debug build, this macro will be ignored; during release build, you will get an error message which will point to the code you need to fix. You can use this macro to remind you, for example, to update the version string, or to fix some debug code which should not be part of the release build.

Example

C++
#include "stdafx.h"
#include <windows.h>

FIXME //update version string before release
int _tmain(int argc, _TCHAR* argv[])
{
  FIXME
  printf("password is *bill*\n");
  return 0;
}

The above code will produce the following output during release build:

1>building...
1>test.cpp
1>.\test.cpp(4) : error C666: found FIXME in release build!
1>.\test.cpp(8) : error C666: found FIXME in release build!
1>pragmatest - 2 errors, 0 warnings
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========

You can click on the error message to jump directly to the FIXME keyword.

How It Works

Put the following code into stdafx.h:

C++
#define __STR2__(x) #x
#define __STR1__(x) __STR2__(x)
#define __LOC2__ __FILE__ "("__STR1__(__LINE__)") : "

#ifdef NDEBUG
  #define FIXME __pragma(message(__LOC2__ "error C666: found FIXME in release build!"))
#else
  #define FIXME
#endif

The FIXME macro is defined depending on if you make a debug or release build. On debug build, #define FIXME is used, which does nothing. On release build, pragma(message(__LOC2__ "error C666: found FIXME in release build!")) is set. It will display the file and the line number of the FIXME macro in the output window. The trick to display a clickable error message is from the Message with style article.

History

  • 21st May, 2009: Initial post
  • 22nd May, 2009: Minor update

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Farhad Reza10-Nov-16 2:50
Farhad Reza10-Nov-16 2:50 
GeneralAuthors Tip: exclude macro definition from Visual Studio text search Pin
Jochen Baier1-Nov-09 6:27
Jochen Baier1-Nov-09 6:27 
GeneralTip: This can be useful for a lot more than just pragmas Pin
Member 44627649-Jun-09 22:27
Member 44627649-Jun-09 22:27 
GeneralTip Pin
alex__b5-Jun-09 5:29
professionalalex__b5-Jun-09 5:29 
Nice and useful!

As it is, the macro displays the error message and stops the compilation. If you only need reminder messages, just replace "error" with "warning" in the macro body. Smile | :)

alex

'Architecture is music frozen in space.'

GeneralNot working Pin
DaTxomin24-May-09 17:07
DaTxomin24-May-09 17:07 
GeneralRe: Not working Pin
Jochen Baier24-May-09 23:05
Jochen Baier24-May-09 23:05 
GeneralRe: Not working Pin
DaTxomin25-May-09 0:56
DaTxomin25-May-09 0:56 
GeneralRe: Not working Pin
DaTxomin25-May-09 1:22
DaTxomin25-May-09 1:22 
GeneralRe: Not working Pin
Jochen Baier7-Jun-09 6:23
Jochen Baier7-Jun-09 6:23 
GeneralRe: Not working Pin
nenfa2-Aug-10 2:52
nenfa2-Aug-10 2:52 
QuestionVery nice, but could it be enhanced? Pin
Willi Deutschmann22-May-09 11:29
Willi Deutschmann22-May-09 11:29 
AnswerRe: Very nice, but could it be enhanced? Pin
Jochen Baier22-May-09 12:21
Jochen Baier22-May-09 12:21 
GeneralRe: Very nice, but could it be enhanced? Pin
zengkun1008-Jun-09 21:52
zengkun1008-Jun-09 21:52 
GeneralMessage Closed Pin
28-Dec-15 1:29
Member 1220655228-Dec-15 1:29 
Generalvery cool Pin
jeffie10022-May-09 9:52
jeffie10022-May-09 9:52 
GeneralRe: very cool Pin
Member 1199807520-Sep-15 6:37
Member 1199807520-Sep-15 6:37 
GeneralNice, simple, and straightforward Pin
Harold Bamford22-May-09 8:14
Harold Bamford22-May-09 8:14 
GeneralRe: Nice, simple, and straightforward Pin
Jochen Baier22-May-09 12:51
Jochen Baier22-May-09 12:51 
GeneralRe: Nice, simple, and straightforward Pin
feanorgem2-Jun-09 15:45
feanorgem2-Jun-09 15:45 
GeneralRe: Nice, simple, and straightforward Pin
Jochen Baier7-Jun-09 6:26
Jochen Baier7-Jun-09 6:26 
GeneralRe: Nice, simple, and straightforward Pin
feanorgem7-Jun-09 9:29
feanorgem7-Jun-09 9:29 
GeneralRe: Nice, simple, and straightforward Pin
zengkun1007-Jun-09 17:28
zengkun1007-Jun-09 17:28 
GeneralMessage Closed Pin
20-Sep-15 6:41
Member 1199807520-Sep-15 6:41 
GeneralMessage Closed Pin
20-Sep-15 6:39
Member 1199807520-Sep-15 6:39 
GeneralMessage Closed Pin
20-Sep-15 6:39
Member 1199807520-Sep-15 6:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.