有没有办法知道我是否在特定的Microsoft Visual Studio版本下进行编译?
我有一个跨平台应用程序,在我的一些函数中,并没有使用传递给函数的所有值.因此我收到GCC的警告,告诉我有未使用的变量.
编码警告的最佳编码方式是什么?
围绕这个功能的#ifdef?
#ifdef _MSC_VER
void ProcessOps::sendToExternalApp(QString sAppName, QString sImagePath, qreal qrLeft, qreal qrTop, qreal qrWidth, qreal qrHeight)
#else
void ProcessOps::sendToExternalApp(QString sAppName, QString sImagePath, qreal /*qrLeft*/, qreal /*qrTop*/, qreal /*qrWidth*/, qreal /*qrHeight*/)
#endif
{
Run Code Online (Sandbox Code Playgroud)
这太丑了,但似乎是编译器喜欢的方式.
或者我在函数末尾为变量赋值为零?(我讨厌它,因为它改变了程序流程中的某些东西以使编译器警告静音).
有正确的方法吗?
我正在通过stm研究STM32l151rct6a,我偶然发现了这些MACRO定义
__CC_ARM, __ICCARM__, __GNUC__, __TASKING__
Run Code Online (Sandbox Code Playgroud)
有谁知道他们的意思?
让我们从一些代码开始吧.这是我程序的极简化版本.
#include <stdint.h>
volatile uint16_t dummyColorRecepient;
void updateColor(const uint8_t iteration)
{
uint16_t colorData;
switch(iteration)
{
case 0:
colorData = 123;
break;
case 1:
colorData = 234;
break;
case 2:
colorData = 345;
break;
}
dummyColorRecepient = colorData;
}
// dummy main function
int main()
{
uint8_t iteration = 0;
while (true)
{
updateColor(iteration);
if (++iteration == 3)
iteration = 0;
}
}
Run Code Online (Sandbox Code Playgroud)
该程序编译警告:
./test.cpp: In function ‘void updateColor(uint8_t)’:
./test.cpp:20:25: warning: ‘colorData’ may be used uninitialized in this function [-Wmaybe-uninitialized]
dummyColorRecepient …Run Code Online (Sandbox Code Playgroud)