Gregor Brandt
Gregor Brandt

Reputation: 7799

go to source with custom messages during compile?

In Visual Studio I can include the following macros in the source and during build the message is printed out. I can then double click on the message in the build message window and go to the line of source.

#define _QUOTE(x) # x
#define QUOTE(x) _QUOTE(x)
#define __FILE__LINE__ __FILE__ "(" QUOTE(__LINE__) ") : "
#pragma message ( __FILE__LINE__ "Notify user of something in code" )

Is it possible to do the same in Builder C++?

I think not, as there seems to be more information in the build messages window in Builder C++ that allows the 'view source' option or double click command to work.

C++ Builder XE.

I have included the Delphi tag with this question as lots of Delphi users also use Builder C++.

Upvotes: 4

Views: 973

Answers (2)

David
David

Reputation: 13580

The equivalent in C++ Builder is the #warning directive. The line:

#warning Test warning message here

Shows the following in the Messages pane:

A warning message in the Messages pane

This acts like any other compiler message, and double-clicking it takes you to the line of code.

The __FILE__ and __LINE__ macros do not expand inside a message you define using #warning - it takes text and spits it out exactly as written. However, you don't need to use them since the message that's emitted includes the file and line number anyway.

If you want to write out an error message (as Delphi allows you to - $MESSAGE has a level, from memory, of hint, warning or error) you can use #error. It works the same as #warning and stops compilation at that line just like any other error compiling, so

#error This is an error message

gives

An error message in the Messages pane

I'm using C++ Builder 2010, but I'm moderately sure that these directives have worked for many versions.

(By the way, tagging a C++ Builder question 'delphi' is normally fine, since many questions about the IDE or VCL will be equally answerable by both communities. I do it all the time. This is probably not one of those questions, since Delphi people are unlikely to know about specific C++ Builder compiler directives. Tagging 'c++-builder' by itself is fine.)

Upvotes: 3

Marjan Venema
Marjan Venema

Reputation: 19356

In Delphi you can include a message directive. For example:

{$MESSAGE WARN 'To be or not to be'}

Which would output a warning in the build messages. That build message is just as clickable as any other compiler error/warning/hint and clicking it will take you to the location of the {$MESSAGE ...} directive in the source.

I do not know as I do not use C++ builder, but I would assume that C++ Builder supports a similar technique...

Upvotes: 0

Related Questions