在C/C++中是否可以嵌套预处理器#define(在本例中#ifdef)?我希望能够这样做:
#ifdef _DEBUG_
#define __DEV_MODE_VERBOSE__ // Defined in DEBUG mode only
#endif
Run Code Online (Sandbox Code Playgroud)
这个想法是" __DEV_MODE_VERBOSE__"通常会被注释掉.取消注释后,我可以使用以下内容:
#ifdef __DEV_MODE_VERBOSE__
int test = (5 * GetTickCount()); // Not reached!
#endif // __DEV_MODE_VERBOSE__
Run Code Online (Sandbox Code Playgroud)
记录通过我的通讯链接发送和接收的命令.#define但是,如果意外地取消注释,则不会在RELEASE(以及生产)代码中进行日志记录.
当我尝试__DEV_MODE_VERBOSE__如上所述定义" "时,它没有定义,因此我不确定语法是否不正确或问题是否更为基础.如果我不在" "和"它" 之间嵌套,则定义符号.#ifdef _DEBUG_#endif
我正在 Visual Studio Code 中测试 C++17 Fallthrough属性。IDE 已配置为使用 Microsoft Visual Studio cl.exe 编译器编译 C/C++ 代码。我在调试模式下tasks.json构建简单文件的任务定义(在 )是:.cpp
{
"type": "shell",
"label": "cl.exe: Build active file",
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/Fe:",
"${file}",
"/link",
"/OUT:${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$msCompile"
]
}
Run Code Online (Sandbox Code Playgroud)
这已经在多个程序上进行了测试并且效果良好。现在我包含一个switch使用新[[fallthrough]];属性的语句,编译器会生成:
warning C5051: attribute 'fallthrough' requires at least '/std:c++17'; ignored
Run Code Online (Sandbox Code Playgroud)
添加"/std:c++17",到 cl.exe 的“args”没有任何改变(生成相同的编译器警告)。这是新版本:
"args": [
"/Zi",
"/EHsc",
"/Fe:",
"/std:c++17",
"${file}",
"/link",
"/OUT:${fileDirname}\\${fileBasenameNoExtension}.exe"
],
Run Code Online (Sandbox Code Playgroud)
据我所知,根据Microsoft …
我的理解是,自Delphi 2009以来,编译器只接受数据类型Integer.然而,也有大量的诸如物品实施例1和实施例2示出了混合的(!)的使用integer和Integer.AFAIK,Embarcadero网站专门使用Integer(好!)但是关于Pascal的维基百科文章专门使用integer.
不幸的是,我没有进入到另一个Pascal编译器,但德尔福7,可同时接收integer和Integer:
int1: Integer;
int2: intEGER; // Allowed in Delphi 7
struct1: MyRecord;
struct2: mYrEcOrD; // Also allowed => source of bugs!
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我Pascal是否正式区分大小写,以及这是否随最新的Delphi编译器而改变.
我们ShowHint启用了TListView .在OnInfoTip处理程序中,构造一个特定于鼠标悬停在其上的项目的提示消息.该消息可能包括换行符(#13#10).
已创建覆盖以处理CM_HINTSHOW消息,并且可以看到要显示的提示消息msg.HintInfo.HintStr.有可能在运行时计算大小,但这似乎有风险,因为实现细节可能很复杂或与平台有关.
可以THintInfo查询其边界矩形还是有另一种方法来确定弹出提示消息显示时的确切大小?
这是必需的,因此msg.HintInfo.HintPos可以设置提示()的确切位置.
我们有一个传统的Delphi 7应用程序,它启动Windows Defrag和屏幕键盘应用程序,如下所示:
// Defragmentation application
ShellExecute(0, 'open', PChar('C:\Windows\System32\dfrg.msc'), nil, nil, SW_SHOWNORMAL);
// On-screen keyboard
ShellExecute(0, 'open', PChar('C:\Windows\System32\osk.exe'), nil, nil, SW_SHOWNORMAL);
Run Code Online (Sandbox Code Playgroud)
两者都适用于Windows XP但在Windows 10上失败.我发现碎片整理应用程序已更改名称dfrgui.exe,但更新代码无济于事.仍然osk.exe在Windows 10上调用屏幕键盘.
这两个应用程序都可以从命令行手动/直接启动,也可以在Windows资源管理器中双击它们.
我怀疑是Windows安全是防止我的应用程序发动的任何东西C:\Windows\System32,因为我可以从启动其他几个应用程序Program Files和C:\Windows.
有人可以帮忙吗?
使用版本0.98.11013.假设我在我的脚本中测试以下代码:
for (num in 1:5)
{
# Print numbers from 1 to the loop variable
print(1:num)
}
Run Code Online (Sandbox Code Playgroud)
当我跨过每一行(使用CTRL + R)时,我在控制台中获得以下输出:
> for (num in 1:5)
+ {
+ # Print numbers from 1 to the loop variable
+ print(1:num)
+ }
[1] 1
[1] 1 2
[1] 1 2 3
[1] 1 2 3 4
[1] 1 2 3 4 5
>
Run Code Online (Sandbox Code Playgroud)
现在,说我在我的代码中犯了一个错误并忘记了结束括号}:
for (num in 1:5)
{
# Print numbers from 1 to the loop variable
print(1:num) …Run Code Online (Sandbox Code Playgroud) 我一直在寻找 C# 中本地结构的替代方案,这在 C/C++ 中是可能的,但在 C# 中是不可能的。这个问题让我了解了 C# 7.0 (.NET 4.7) 中出现的轻量级 System.ValueTuple 类型。
假设我有两个以不同方式定义的元组:
var book1 = ("Moby Dick", 123);
(string title, int pages) book2 = ("The Art of War", 456);
Run Code Online (Sandbox Code Playgroud)
两个元组都包含两个元素。的类型Item1为System.String,并且 的类型Item2在System.Int32两个元组中。
如何确定元组变量中元素的数量?您可以使用类似的方法迭代这些元素吗foreach?
快速阅读System.ValueTuple 的官方文档似乎没有这些信息。
Visual Studio 2019 中的 MSTest v2 相对较新。该属性指示该方法应在每个测试之前TestInitialize运行。同样,指示该方法应在每次测试后运行。TestCleanup
[TestInitialize()]
public void Setup()
{
// This method will be called before each MSTest test method
}
[TestCleanup()]
public void Teardown()
{
// This method will be called after each MSTest test method has completed
}
Run Code Online (Sandbox Code Playgroud)
如果你的测试类有N个方法,上面的方法将运行N次。
有没有一种方法可以发出只运行一次的类似设置和拆卸的方法的信号?换句话说,对于所有 N 个测试的每次完整运行,每个方法将仅运行一次。
NUnit3 和 xUnit v2.4.0 是否有类似的机制?
我试图覆盖虚拟TThread :: Terminate方法,但我发现只有在设置Terminated标志后才会调用我的覆盖.实现这个的正确方法是什么?
TTestThrd = class(TThread)
private
{ Private declarations }
protected
{ Protected declarations }
procedure Execute(); override;
procedure DoTerminate(); override;
public
{ Public declarations }
end;
procedure TTestThrd.Execute();
var
bTerminated: Boolean;
begin
// This is the main thread loop
try
while (not Terminated) do
begin
// Sleep or use TEvent::Waitfor...
end;
finally
// Terminated (or exception) so free all resources...
bTerminated := True; // Why is this called...
end;
end;
procedure TTestThrd.DoTerminate();
var
bDoTerminateCalled: …Run Code Online (Sandbox Code Playgroud) 在命名空间的上下文中是否static意味着什么?func2两种方法看起来是等效的。
// MyHeader.h
namespace TestNameSpace
{
int func1() { return 1; }
static int func2() { return 2; }
}
// SomeFile.cpp
#include "MyHeader.h"
// ...
int test1 = TestNameSpace::func1(); // 1
int test2 = TestNameSpace::func2(); // 2
Run Code Online (Sandbox Code Playgroud) 以下代码返回计算机的第一个TCP/IP连接的IP地址.
uses WinSock;
// ...
function GetLocalIP() : String;
var
addr: TSockAddrIn;
phe: PHostEnt;
szHostName: array[0..128] of Char;
socketData: TWSADATA;
begin
Result := '127.0.0.1';
// Initialize the socket API
if (WSAStartup($101, socketData) = 0) then
begin
// Get local machine name
if (GetHostName(szHostName, 128) = SOCKET_ERROR) then
Exit;
// Use name to find IP address
phe := GetHostByName(szHostName);
if (phe = nil) then
Exit;
addr.sin_addr.S_addr := Longint(PLongint(phe^.h_addr_list^)^);
// Convert IP address to PChar format
Result := inet_ntoa(addr.sin_addr);
end;
end;
// …Run Code Online (Sandbox Code Playgroud)