Going to the source with custom messages at compile time?

In Visual Studio, I can include the following macros in the source code and a message is displayed during the build. Then I can double-click the message in the build message box and go to the source line.

#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, because more information appears in the build message box in Builder C ++ that allows you to use the "view source" option or double-click command.

C ++ Builder XE.

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

+4
source share
2 answers

Equivalent in C ++ Builder is the #warning directive. Line:

 #warning Test warning message here 

Shows the following in the Messages panel:

A warning message in the Messages pane

It acts like any other compiler message, and with a double click you get into a line of code.

The __FILE__ and __LINE__ do not expand inside the message that you define using #warning - it accepts the text and spits it out exactly as it is written. However, you do not need to use them, since the message that emitted in any case includes a file and a line number.

If you want to write an error message (since Delphi allows - $MESSAGE has a level of memory, hints, warnings or errors), you can use #error . It works just like #warning and stops compiling on this line like any other error compilation, therefore

 #error This is an error message 

gives

An error message in the Messages pane

I use C ++ Builder 2010 , but I am confident that these directives worked for many versions.

(By the way, marking the C ++ Builder β€œdelphi” question is usually fine, since many questions about the IDE or VCL will answer both communities equally. I do this all the time. This is probably not one of those questions, since Delphi people are unlikely whether they learn about specific C ++ Builder compiler directives. The mark "C ++ - builder" by itself is okay.)

+3
source

In Delphi you can enable the message directive. For instance:

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

Which displays a warning in assembly messages. This build message is as accessible as any other compiler error / warning / hint, and clicking on it will lead you to the location of the {$ MESSAGE ...} directive in the source.

I do not know, since I do not use the C ++ constructor, but I would suggest that C ++ Builder supports a similar technique ...

0
source

Source: https://habr.com/ru/post/1334553/


All Articles