Sometimes you just need to suppress only some warnings, and you want to keep other warnings in order to be safe. In code, you can suppress warnings for variables and even formal parameters using an unused GCC attribute. Let's say you have this piece of code:
void func(unsigned number, const int version) { unsigned tmp; std::cout << number << std::endl; }
A situation may arise when you need to use this function as a handler, which (imho) is quite common in the C ++ Boost library. Then you need the second formal parameter version , so the function signature matches what the handler needs, otherwise compilation will fail. But you really do not need this in the function itself ...
The decision on how to mark a variable or formal parameter that should be excluded from warnings is as follows:
void func(unsigned number, const int version __attribute__((unused))) { unsigned tmp __attribute__((unused)); std::cout << number << std::endl; }
GCC has many other parameters, you can check them on the manual pages. This also works for C programs, not just C ++, and I think that it can be used for almost every function, not just handlers. Go and try!;)
PS: Recently, I used this to suppress Boosts serialization warnings in a template as follows:
template <typename Archive> void serialize(Archive &ar, const unsigned int version __attribute__((unused)))
EDIT: Apparently, I did not answer your question at your request, drak0sha did it better. This is because I basically followed the title of the question, my bad. Hope this can help other people who get here because of this name ... :)
Dee'Kej Apr 28 '14 at 2:22 2014-04-28 02:22
source share