User warnings for MS Visual Studio

Posted by kent at 9 April 2010

Category: Dev, c++

Tags: , ,

This little macro prints out user warnings to the output window in a format the “Error List” within Visual Studio will understand and parse. Taken from Stack Overflow and modified a little.

#define STRINGISE_IMPL(x) #x
#define STRINGISE(x) STRINGISE_IMPL(x)

	// Use: #pragma message WARN("My message")
#if _MSC_VER
#   define FILE_LINE_LINK __FILE__ "(" STRINGISE(__LINE__) ") : "
#   define WARN(exp) (FILE_LINE_LINK "warning: " exp)
#else//__GNUC__ - may need other defines for different compilers
#   define WARN(exp) ("WARNING: " exp)
#endif

It will produce output like this:

1>.\src\bug.cpp(82) : warning: check me

When this line is present in the source file.

#pragma message WARN("check me")

Related posts:

  1. Visual Studio 2010, TR1 and Boost.
  2. Visual Studio: fatal error LNK1201: error writing to program database ‘…’ check for insufficient disk space, invalid path, or insufficient privilege

Leave a Reply

Leave a Reply
  • (required)
  • (required) (will not be published)