Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unused parameter warning

I am getting "unused parameter 'testString'" warning from following code. But I am using testString to log. So how come it is unused ?

- (void)getString:(NSString *)testString {
          ICELogInfo(@"%@", testString);
}

ICELogInfo is a macro for NSLog.

#define ICELogInfo(fmt, ...) LOG_FORMAT(fmt, @"INFO", ##__VA_ARGS__)
#define LOG_FORMAT(fmt, lvl, ...) LOG_FORMAT_NO_LOCATION(fmt, lvl, ##__VA_ARGS__)
#define LOG_FORMAT_NO_LOCATION(fmt, lvl, ...) NSLog((@"%@ " fmt), lvl, ##__VA_ARGS__)

What I am doing wrong ?

like image 298
AAV Avatar asked Jul 09 '13 18:07

AAV


People also ask

How do I get rid of the unused variable warning?

Solution: If variable <variable_name> or function <function_name> is not used, it can be removed. If it is only used sometimes, you can use __attribute__((unused)) . This attribute suppresses these warnings.

What does unused mean in C?

In GCC, you can label the parameter with the unused attribute. This attribute, attached to a variable, means that the variable is meant to be possibly unused. GCC will not produce a warning for this variable.

What are unused variables?

An unused variable refers to a variable of which the data element structure is unreferenced in the main program, including the parent and the subordinate items. An unused copybook refers to a copybook with the aforementioned copybook of an unused variable.

Do unused variables take up memory?

Does an unused member variable take up memory? No (if it is "really" unused).


2 Answers

You aren't doing something wrong. This is a common problem when using macros.

As a workaround if you want to get rid of the warning, you can use this code:

- (void)getString:(NSSTring*) __unused testString {
          ICELogInfo(@"%@", testString);
}
like image 63
gsach Avatar answered Nov 10 '22 19:11

gsach


I've run into the same "problem" before. Solved it by using the unused flag as e.g.

- (void)getString:(NSString *)testString {
    ICELogInfo(@"%@", testString);
    #pragma unused (testString)
}
like image 2
Groot Avatar answered Nov 10 '22 20:11

Groot