J
John Fisher
void f(int p)
{
}
Many (most?) compilers will report that p is unreferenced here. This may not
be a problem as f may have to match some common prototype. Typically
pointers to functions are involved.
For a long time I have used
#define UNUSED(p) ((void)(p))
so that
void f(int p)
{
UNUSED(p);
}
will not cause a warning on all compilers I have tried it with. However a
third party code vendor uses
#define UNUSED(p) { (p) = (p); }
I believe this code has been ported to many different compilers. On my
compiler this will produce a useless assignment warning, so for that reason
I obviously prefer my approach.
What's your favourite trick and why? Which approach do you think is more
likely to prevent a warning? Has anyone done a survey?
{
}
Many (most?) compilers will report that p is unreferenced here. This may not
be a problem as f may have to match some common prototype. Typically
pointers to functions are involved.
For a long time I have used
#define UNUSED(p) ((void)(p))
so that
void f(int p)
{
UNUSED(p);
}
will not cause a warning on all compilers I have tried it with. However a
third party code vendor uses
#define UNUSED(p) { (p) = (p); }
I believe this code has been ported to many different compilers. On my
compiler this will produce a useless assignment warning, so for that reason
I obviously prefer my approach.
What's your favourite trick and why? Which approach do you think is more
likely to prevent a warning? Has anyone done a survey?