Click here to Skip to main content
Click here to Skip to main content

FIXME - A Smart FIXME Macro

By , 25 May 2009
 

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

#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:

#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)

About the Author

Jochen Baier
Germany Germany
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralAuthors Tip: exclude macro definition from Visual Studio text searchmemberJochen Baier1 Nov '09 - 6:27 
Problem:
 
if you search for "FIXME" with Visual Studio in the whole project, you will get results pointing to the macro definition.
 
Solution:
 
put the macro definition in a separate header file but do NOT add this file to your project. With this trick the macro still works but the header file will not be search through.
GeneralTip: This can be useful for a lot more than just pragmasmemberMember 44627649 Jun '09 - 22:27 
This code snippet can also be used to comfortably display line numbers when making an exception. I've got it in my project and it's very nice for error tracking.
GeneralTipmemberalex__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 workingmemberDaTxomin24 May '09 - 17:07 
I have included the macro as shown and I get the following errors:
 
... : error C2065: '__pragma' : undeclared identifier
... : cerror C2065: 'message' : undeclared identifier
... : error C2146: syntax error : missing ';' before identifier ...
 
I'm using VC6, in case it matters.
 
The idea you propose sounds great. If I could get it to work, I could use it for TODO's too.
 
I hope you know what the heck is up with these errors.
 
Thanks.
GeneralRe: Not workingmemberJochen Baier24 May '09 - 23:05 
maybe VC6 is too old....
 
you can test if #pragma __pragma and message() is working if you use only ONE
of the following lines in each test:
 
#pragma once
__pragma once
#pragma message("hallo")
GeneralRe: Not workingmemberDaTxomin25 May '09 - 0:56 
Maybe I'm too old. Darn it, I cannot make sense of what you are suggesting I do.
GeneralRe: Not workingmemberDaTxomin25 May '09 - 1:22 
Ok, perhaps I understood.
 
I tested them all and the problem is __pragma. That's the one that isn't working.
GeneralRe: Not workingmemberJochen Baier7 Jun '09 - 6:23 
hi,
 
you could try following trick:
 

#define __STR2__(x) #x
#define __STR1__(x) __STR2__(x)
#define __LOC2__ __FILE__ "("__STR1__(__LINE__)") : "
 
#ifdef NDEBUG
  #define FIXME message(__LOC2__ "error C666: found FIXME in release build!")
#else
  #define FIXME 
#endif
 

use:
 
int _tmain(int argc, _TCHAR* argv[])
{
  #pragma FIXME
  return 0;
}
 
if its working with vs6 i will update the article so please let me know if its working.
 
thanks jochen
GeneralRe: Not workingmembernenfa2 Aug '10 - 2:52 
it can work, thx Big Grin | :-D
QuestionVery nice, but could it be enhanced?memberWilli Deutschmann22 May '09 - 11:29 
Could this be enhanced to display an [optional] additional message to serve as a reminder what to fix?
 
e.g.:
 
FIXME("activate License")
 
1>.\test.cpp(4) : error C666: found FIXME in release build: "activate License".
 

Very cool nonetheless!
 
Seven days without coffee makes one weak.

AnswerRe: Very nice, but could it be enhanced?memberJochen Baier22 May '09 - 12:21 
yes:
 

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

GeneralRe: Very nice, but could it be enhanced?memberzengkun1008 Jun '09 - 21:52 
Jochen Baier wrote:
#define FIXME(text) __pragma(message(__LOC2__ "error C666: found FIXME in release build! (" text ")"))

 
it should be
 
#define FIXME(text) __pragma(message(__LOC2__ "error C666: found FIXME in release build! (" #text ")"))
 
A Chinese VC++ programmer

Generalvery coolmemberjeffie10022 May '09 - 9:52 
this is clever - thanks
GeneralNice, simple, and straightforwardmemberHarold Bamford22 May '09 - 8:14 
I like it!
 
I do wonder about the #else condition. Why not just make it:
 
#else
#define FIXME
#endif

GeneralRe: Nice, simple, and straightforwardmemberJochen Baier22 May '09 - 12:51 
thanks for the hint,
 
I have sended an update request to codeproject.
 

jochen
GeneralRe: Nice, simple, and straightforwardmemberfeanorgem2 Jun '09 - 15:45 
Also, the __pragma is a MS specific keyword for use of pragmas within macros starting with VS 2005.
 
There is no need for __STR1__ remaping to __STR2__, you can go straight to __STR2__
 
Jay
GeneralRe: Nice, simple, and straightforwardmemberJochen Baier7 Jun '09 - 6:26 
mmh ? don't work for me without #define __STR1__(x) __STR2__(x)
 
can you give an example ?
 
thanks jochen
GeneralRe: Nice, simple, and straightforwardmemberfeanorgem7 Jun '09 - 9:29 
That would be because you are using VS2005 not VS6 since you have __pragma available to you.
 
But here is an enhanced version that works in VS6 and adds clickable or not option as well as warning levels:
#ifdef _MSC_VER               // Microsoft Visual Studio 6.0 (== 1200)
   #if (_MSC_VER == 1200)     // Microsoft Visual Studio 6.0
      // fix variable scope bug in for loops to comply with VS 2005
      // and ANSI C++ standards
      #define  for   if (false); else for
   #endif   // (_MSC_VER == 1200)

   // status and warning message definition macros (file, line, message).
   // with the colon in the message it becomes clickable, without it
   //    the message is only informatory
   #define  __LINE_STR__(x)   #x  // stringizer for __LINE__
   #ifndef MESSAGE_LEVEL      // set default level to ignore macros
      #define  MESSAGE_LEVEL  1   // no messages
   #endif   // MESSAGE_LEVEL
   #if MESSAGE_LEVEL == 1     // no messages
      #define  WARNING(str)   comment( compiler)
   #else                      // click on warnings
      #define  __WARNING__(x) __FILE__ "(" __LINE_STR__(x)\
                              ") : *** WARNING *** The compile switch "
      #define  WARNING(str)   message( __WARNING__(__LINE__) #str\
                              " is enabled")
   #endif   // MESSAGE_LEVEL == 1

   #if MESSAGE_LEVEL <= 2     // skip info messages
      #define  IS_ENABLED(str)   comment( compiler)
      #define  NOT_ENABLED(str)  comment( compiler)
   #else
      #if MESSAGE_LEVEL == 3  // print info messages
         #define  __RPARAN__  ") "   // informatory message
      #else                   // click on info messages
         #define  __RPARAN__  ") : "   // clickable message
      #endif   // MESSAGE_LEVEL == 3
      #define  __PREFIX__(x)  __FILE__ "(" __LINE_STR__(x) __RPARAN__\
                              "The compile switch "
      #define  IS_ENABLED(str)   message( __PREFIX__(__LINE__) #str\
                                 " is enabled")
      #define  NOT_ENABLED(str)  message( __PREFIX__(__LINE__) #str\
                                 " is *** NOT *** enabled")
   #endif   // MESSAGE_LEVEL <= 2
#endif   // _MSC_VER
 
With this you can do things such as:
  #ifdef COMPILE_THIS   // include this block if the definition exists
    #pragma IS_ENABLED( COMPILE_THIS)  // good for knowning when blocks are compiled in or not
    #pragma WARNING( COMPILE_THIS)   // or more severe, counts as a warning message
    // add conditional code here
  #else
    #pragma NOT_ENABLED( COMPILE_THIS)
    // add conditional code here
  #endif   // COMPILE_THIS

GeneralRe: Nice, simple, and straightforwardmemberzengkun1007 Jun '09 - 17:28 
If you don't use __STR1__, VS2005 will jump to a wrong line when you click the FIXME error in the output window.
 
A Chinese VC++ programmer

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 25 May 2009
Article Copyright 2009 by Jochen Baier
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid