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 ?
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.
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.
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.
Does an unused member variable take up memory? No (if it is "really" unused).
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);
}
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)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With