在编译期间使用自定义消息转到源代码?
在 Visual Studio 中,我可以在源代码中包含以下宏,并在构建过程中打印出消息。然后,我可以双击构建消息窗口中的消息并转到源代码行。
#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" )
是否可以在 Builder C++ 中执行相同的操作?
我认为不是,因为 Builder C++ 中的构建消息窗口中似乎有更多信息,允许“查看源代码”选项或双击命令起作用。
C++ Builder XE。
我在这个问题中包含了 Delphi 标签,因为许多 Delphi 用户也使用 Builder C++。
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++.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
C++ Builder 中的等效项是
#warning
指令。该行:在消息窗格中显示以下内容:
这与任何其他编译器消息类似,双击它会将您带到代码行。
__FILE__
和__LINE__
宏不会在您使用#warning
定义的消息内展开 - 它获取文本并完全按照编写的内容吐出。但是,您不需要使用它们,因为发出的消息无论如何都包含文件和行号。如果您想写出错误消息(Delphi 允许您 -
$MESSAGE
根据记忆具有提示、警告或错误级别),您可以使用#error
。它的工作方式与#warning
相同,并在该行停止编译,就像任何其他错误编译一样,因此给出
我正在使用 C++ Builder 2010,但我我相当确定这些指令适用于许多版本。
(顺便说一句,将 C++ Builder 问题标记为“delphi”通常没问题,因为有关 IDE 或 VCL 的许多问题将由两个社区同等回答。我一直这样做。这可能不是这些问题之一,因为Delphi 人员不太可能了解特定的 C++ Builder 编译器指令,单独标记“c++-builder”就可以了。)
The equivalent in C++ Builder is the
#warning
directive. The line:Shows the following 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, sogives
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.)
在 Delphi 中,您可以包含消息指令。例如:
这会在构建消息中输出警告。该构建消息与任何其他编译器错误/警告/提示一样可单击,单击它会将您带到源代码中 {$MESSAGE ...} 指令的位置。
我不知道,因为我不使用 C++ 构建器,但我假设 C++ 构建器支持类似的技术......
In Delphi you can include a message directive. For example:
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...