devxlogo

Create #pragma Messages to Reach the Source of a Message

Create #pragma Messages to Reach the Source of a Message

This macro is for use in #pragma messages. It allows you to double-click on an output message and automatically open the file in the editor at the source #pragma message statement:

#define STRING2(x) #x#define STRING(x) STRING2(x)#define FILE_LOC __FILE__ "(" STRING(__LINE___) ") : "

Usage:

#pragma message(FILE_LOC "Your message here")

When compiling, this will generate output like:

c:My ProjectsMyFile.cpp(27) : Your message here

When you double-click on the message, MyFile.cpp will open to line 27. Note that this is IDE-dependent; it relies on mimicking the format that Visual Studio uses for build warnings and errors. I’ve used it in Visual Studio 6 and 2005; your mileage may vary in other IDEs.

See also  How to Avoid Money Transfer Scams  
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist