[英]Macro meaning in c++
我碰巧在c ++代碼( https://github.com/LairdCP/UwTerminalX )中遇到了如下所示的宏定義。
#define SpeedModeInactive 0b00
#define SpeedModeRecv 0b01
#define SpeedModeSend 0b10
#define SpeedModeSendRecv 0b11
當我嘗試使用Visual Studio 2010進行編譯時,出現以下錯誤。
Error 14 error C2059: syntax error : ')'
這個宏的含義是什么? 宏的用法如下所示。
if ((gchSpeedTestMode == SpeedModeSendRecv || gchSpeedTestMode == SpeedModeRecv) && (gintSpeedBytesReceived10s > 0 || ui->edit_SpeedBytesRec10s->text().toInt() > 0))
{
//Data has been received in the past 10 seconds: start a timer before stopping to catch the extra data packets
gchSpeedTestMode = SpeedModeRecv;
gtmrSpeedTestDelayTimer = new QTimer();
gtmrSpeedTestDelayTimer->setSingleShot(true);
connect(gtmrSpeedTestDelayTimer, SIGNAL(timeout()), this, SLOT(SpeedTestStopTimer()));
gtmrSpeedTestDelayTimer->start(5000);
//Show message that test will end soon
ui->statusBar->showMessage("Waiting 5 seconds for packets to be received... Click cancel again to stop instantly.");
}
這是因為Visual Studio無法識別二進制值(以0bXXX開頭),但是您可以像這樣簡單地將其定義為十六進制值:
#define SpeedModeInactive 0x0
#define SpeedModeRecv 0x1
#define SpeedModeSend 0x2
#define SpeedModeSendRecv 0x3
二進制文字的使用最早是在C ++ 14中引入的,VS2010不支持該二進制文字, https: //en.wikipedia.org/wiki/C%2B%2B14#Binary_literals
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.