- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用的是 GCC 版本 8.2在几段代码中,我使用了小函数。我对每一项功能都进行了测试(即 Unity 框架测试)。测试被定义为 #define 宏,测试非常具体的事情。例如,如果一个数字是正数。
现在,当使用 -Wextra 标志编译代码时,我收到有关未使用变量的警告,尽管我在定义的宏上使用它们。
问题是,GCC 无法将宏识别为使用变量,还是我遗漏了什么?
示例:
#define compare(a,b) ( ((a) == (b)) ? 1 : 0 )
...
void f() {
int a;
a = f1();
if(compare(a,123))
printf("It works");
}
在这种情况下,GCC 会警告未使用的变量 a,尽管它正在被宏使用(除了由函数 f1() 赋予值之外)。
最佳答案
情况并非如此,至少在您提供的示例中是这样。这是Minimal, Complete, and Verifiable演示:
#include <stdio.h>
#define compare(a,b) ( ((a) == (b)) ? 1 : 0 )
int f1() {
return 42;
}
void f() { // your code
int a;
a = f1();
if (compare(a, 123))
printf("It works");
}
int main(int argc, char *argv[]) {
f();
return 0;
}
当使用 gcc 8.2 或 7.3 与 gcc -Wall -Wunused
进行编译时(是的,这是多余的),没有警告或错误。
关于c - GCC Wunused-variable 对已使用的变量发出警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54243687/
我正在学校作业中实现单例设计模式,这是我的类头文件: class Scheduler { public: static Scheduler * instance(); ~Schedul
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
最近我开始用C++编程了(我是Java出身的,有点零钱哈哈)。在 Windows 下一切正常。问题是我切换到 Linux,这就是我遇到编译器问题的地方。通常当你声明一个变量但没有被使用时,编译器会显示
我是 c++ 新手。 我想忽略警告 -Wunused-result 我猜是因为 -Wall 标志而弹出的。 我在网上搜索了一下,发现这是我可以通过声明一个pragma 来忽略它。我对 pragma 了
我有以下代码,在使用 gcc-4.6 编译时我收到警告: warning: variable ‘status’ set but not used [-Wunused-but-set-variable]
我将Wunused-parameter用于我的项目,但我想让它忽略3rd Party header (特定目录中的 header )。有什么办法可以用cmake设置它吗? 我目前正在像这样设置编译器选
我使用的是 GCC 版本 8.2在几段代码中,我使用了小函数。我对每一项功能都进行了测试(即 Unity 框架测试)。测试被定义为 #define 宏,测试非常具体的事情。例如,如果一个数字是正数
以下代码生成一个警告,指出未使用 temp(这是真的): #include int f() { return 5; } int main() { if(const int& temp = f
我只是花了一些时间来找出为什么可变集没有正确地与自身相交与另一组,使用 [someMutableSet intersectsSet:anotherSet]; // not the best i
我正在使用以下命令构建 C++14。 g++ -std=c++14 -O2 -Wall -pedantic -pthread main.cpp && ./a.out 如何将 -Wunused-vari
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
我试图通过使用 GCC 的 -Wunused-function 标志在我的代码库中找到未使用的函数。 如我所料,使用 gcc -Wall -Wunused-function main.cpp 编译以下
这是我的代码: #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-variable" //__attribute
我使用 Ideone.com 编译了下面的代码,弹出了以下警告。 rtctimer.c: In function 'rtctimer_next_tick': rtctimer.c:87.7: warn
我已经搜索并没有真正找到并理解这个错误。奇怪的是,我只得到 c、d、e 的错误,而不是 a 和 b 或它们所有的错误。 程序是关于双链表的。 当我编译时会发生这种情况: gcc -Wall -g -c
我正在尝试使用Ubuntu将Cross编译为Android内核。 成功设置menuconfig后,并使用以下选项进行编译: make ARCH=arm CROSS_COMPILE="arm-bravo
所以我试图找出 while 循环和大多数 if 语句,所以我尝试制作这个小游戏,其中你有一定的生命值,怪物也有,只要你们都有超过 0 的生命值,循环就会运行,所以每个循环怪物都会对你造成 50 点伤害
main.cpp #include #include #include "steganography.h" // call steganography class const int arrSi
我有一个使用 SDL 的 C++ 项目。 我在编译时遇到这个错误,我不知道如何解决。 它说: Source/Classes/game.cpp:15:15: advarsel(this means 'w
我已经盯着它看了很久,但不明白为什么它会在 for 循环语句中给我一个警告。 //looks for a certain account by name in the provided list, r
我是一名优秀的程序员,十分优秀!