unused-variables

Unused parameter in c++11

橙三吉。 提交于 2019-11-29 19:55:45
In c++03 and earlier to disable compiler warning about unused parameter I usually use such code: #define UNUSED(expr) do { (void)(expr); } while (0) For example int main(int argc, char *argv[]) { UNUSED(argc); UNUSED(argv); return 0; } But macros are not best practice for c++, so. Does any better solution appear with c++11 standard? I mean can I get rid of macros? Thanks for all! I have used a function with an empty body for that purpose: template <typename T> void ignore(T &&) { } void f(int a, int b) { ignore(a); ignore(b); return; } I expect any serious compiler to optimize the function

Mark unused parameters in Kotlin

心不动则不痛 提交于 2019-11-29 00:51:22
I am defining some functions to be used as callbacks and not all of them use all their parameters. How can I mark unused parameters so that the compiler won't give me warnings about them? bashor With the @Suppress annotation You can suppress any diagnostics on any declaration or expression. Examples: Suppress warning on parameter: fun foo(a: Int, @Suppress("UNUSED_PARAMETER") b: Int) = a Suppress all UNUSED_PARAMETER warnings inside declaration @Suppress("UNUSED_PARAMETER") fun foo(a: Int, b: Int) { fun bar(c: Int) {} } @Suppress("UNUSED_PARAMETER") class Baz { fun foo(a: Int, b: Int) { fun

How can I get rid of an “unused variable” warning in Xcode?

半世苍凉 提交于 2019-11-27 17:55:31
I understand exactly why unused variable warnings occur. I don't want to suppress them in general, because they are incredibly useful in most cases. However, consider the following (contrived) code. NSError *error = nil; BOOL saved = [moc save:&error]; NSAssert1(saved, @"Dude!!1! %@!!!", error); Xcode reports that saved is an unused variable, when of course it isn't. I suspect this is because NSAssert1 is a macro. The NS_BLOCK_ASSERTIONS macro is not defined, so Objective C assertions are definitely enabled. While it doesn't hurt anything, I find it untidy and annoying, and I want to suppress

Mark unused parameters in Kotlin

隐身守侯 提交于 2019-11-27 14:29:03
问题 I am defining some functions to be used as callbacks and not all of them use all their parameters. How can I mark unused parameters so that the compiler won't give me warnings about them? 回答1: With the @Suppress annotation You can suppress any diagnostics on any declaration or expression. Examples: Suppress warning on parameter: fun foo(a: Int, @Suppress("UNUSED_PARAMETER") b: Int) = a Suppress all UNUSED_PARAMETER warnings inside declaration @Suppress("UNUSED_PARAMETER") fun foo(a: Int, b:

Standard conventions for indicating a function argument is unused in JavaScript

牧云@^-^@ 提交于 2019-11-27 05:14:19
Are there any standard ways of marking a function argument as unused in JavaScript, analogous to starting a method argument with an underscore in Ruby? Just so we have an example to work from, this is fairly common with jQuery's $.each where you're writing code that doesn't need the index, just the value, in the iteration callback ( $.each is backward relative to Array#forEach ): $.each(objectOrArrayLikeThing, function(_, value) { } // Use value here }); Using _ is the closest I've seen to a standard way to do that, yes, but I've also seen lots of others — giving it a name reflective of its

How can I get rid of an “unused variable” warning in Xcode?

丶灬走出姿态 提交于 2019-11-26 19:14:03
问题 I understand exactly why unused variable warnings occur. I don't want to suppress them in general, because they are incredibly useful in most cases. However, consider the following (contrived) code. NSError *error = nil; BOOL saved = [moc save:&error]; NSAssert1(saved, @"Dude!!1! %@!!!", error); Xcode reports that saved is an unused variable, when of course it isn't. I suspect this is because NSAssert1 is a macro. The NS_BLOCK_ASSERTIONS macro is not defined, so Objective C assertions are

Standard conventions for indicating a function argument is unused in JavaScript

情到浓时终转凉″ 提交于 2019-11-26 07:47:04
问题 Are there any standard ways of marking a function argument as unused in JavaScript, analogous to starting a method argument with an underscore in Ruby? 回答1: Just so we have an example to work from, this is fairly common with jQuery's $.each where you're writing code that doesn't need the index, just the value, in the iteration callback ( $.each is backward relative to Array#forEach ): $.each(objectOrArrayLikeThing, function(_, value) { } // Use value here }); Using _ is the closest I've seen