- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一小段 C++ 代码:
#include <iostream>
#include <iterator>
#include <string>
using namespace std;
int main() {
int i=0;
istream_iterator<string> EOS;
double x;
return 0;
}
现在我用我的 g++ (GCC) 4.4.4 编译它
g++ -W -Wall -pedantic test.cc -o test
并得到:
test.cc: In function 'int main()':
test.cc:9: warning: unused variable 'i'
test.cc:11: warning: unused variable 'x'
为什么未使用的 EOS 没有警告?
最佳答案
它不是原始值,因此它的构造函数和/或析构函数可能具有预期的副作用。
为了说明这种情况在实践中发生:我使用一个类来为代码段计时,大致如下所示:
class Timed {
double start;
public:
Timed() { start = now(); }
~Timed() { std::cout << (now() - start) << '\n'; }
}
所以为了衡量一个函数需要多长时间,我只是这样做:
void slow() {
Timed t;
// heavy operation here...
}
变量 t
永远不会被使用,但它对代码的行为仍然很重要。
关于c++ - g++ 不显示 'unused' 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49979956/
__attribute__((unused)) 和 __attribute((unused)) 可以将变量标记为未使用以避免未使用警告。 它们有什么区别? 最佳答案 在 GCC 存储库中,在文件 c-
在 Visual Studio 2010(C++,非托管)中调试,信息 unused ??? 或 unused 0 应该是什么意思?我附上了两个屏幕截图, child 是现有窗口的 HWND。 我也对
我只想在我的 Xcode 项目的一个文件中删除此编译器警告。有办法做到这一点吗? 最佳答案 您可以使用 a pragma directive and the "diagnostic" keyword
为什么.NET 警告“未使用的变量”而不是“未使用的参数”? (我相信 Java 在这两种情况下都会发出警告。) 为什么 .NET 不关心“未使用的参数”? 最佳答案 在我看来,您可能真正想要保留未使
我正在处理这个教程应用程序,代码给我这个警告: Xcode WARNING: Unused Entity Issue: Unused Variable 执行这条语句时报错: int newRowInd
考虑以下代码: class Foo { let bar = "Hello world!" init () { self // Warning: Expression o
您好,我正在尝试将 zxing 二维码阅读器整合到我的应用程序中。我直接从谷歌代码网站检查了 svn,并在我的项目设置中添加了所有标题路径。然而,当我尝试构建项目时,我遇到了很多“未使用的函数”和“未
在 Pipes Tutorial ,它说: The concrete type synonyms use () to close unused inputs and X (the uninhabite
我有工作 Swift.2.3 项目,但是当我构建并将其转换为 Swift3 时,它给我: Result of call to (_:parameters:completionHandler:)' is
我有一个基于 cmake 的包。它有几个目标可执行文件。其中一个目标时不时会崩溃。回溯如下: ... #19 XXX::~XXX (this=0x69a120, __in_chrg=) at
我刚刚用 C 编写了我的第一个应用程序,我收到了这个警告(已编辑):unused variable pp int compteur = 1; int *p = &compteur; int **pp
我的 C++ 编译器发出警告,指出以下“intVar”变量“未使用”。 void MyClass::MyMethod(bool bFlag) { int intVar = 10; if
我正在处理一个 Flask 项目,从 API 包装器获取一些数据。包装器返回一个生成器对象,所以我在将其传递给 Flask 的 render_template() 之前打印值(for obj in g
我是 goLang 的新手。我正在尝试从 intellij 构建一个项目,该项目使用 git 库中的一个包: import ( "github.com/aerospike/aerospike-
我收到很多不正确的 ESLint/TS 警告,说枚举案例“已分配一个值但从未使用过”或导入“已定义但从未使用过”。这是一些代码。 所有导入都说它们已定义但从未使用过(尽管您可以看到它们在底部的类型中)
这对我来说真是个谜。我已经这样定义了我的方法(对于类“graf”): addStatistics <- function(x) UseMethod("addStatistics") addStatis
我正在尝试使用 grunt-unused 删除多个子目录中所有未使用的图像链接。 .为清楚起见,这是我的文件夹结构: |-- dist | |-- site-1 | | |—-index.htm
我试图在我通过函数创建的条形图上注释标准消息。以下是代码: hashbar <- function(x) { suppressWarnings(library(stringr))
我在一个过程中有一个变量,我需要保持该变量的事件状态,直到该过程中的匿名方法运行为止,但我不在匿名方法中使用该变量。有没有一种惯用的方法告诉编译器无论如何都要捕获变量? 例如: procedure F
我正在使用 Delphi XE、Windows 7。 在应用程序中,我想启用不同的报告类型供用户选择。为此,我有 1 个基本报告类和每个报告类型(xml、csv、ppt 等)的子类。 {Just an
我是一名优秀的程序员,十分优秀!