Hua_Minghu
(Hua Minghu)
September 21, 2023, 3:52am
1
What language is this for?
C
Which rule?
C S1172
Why do you believe it’s a false-positive/false-negative?
It is normal usage in C
Are you using
SonarQube Developer Edition Version 9.9 (build 65466)
How can we reproduce the problem? Give us a self-contained snippet (best) or screenshot (good)
typedef void (*Run)(int, int);
void BirdRun(int leg, int wing)
{
printf(“birds run %d”, wing);
}
void BirdRun(int leg, int wing)
{
printf(“birds run %d”, wing);
}
void DogRun(int leg, int wing)
{
printf(“dogs run %d”, leg);
}
int main(int argc, char** argv)
{
Run dog = DogRun;
dog(1, 2);
Run bird = BirdRun;
bird(3, 4);
return 0;
}
Remove the unused parameter “leg”.
aalvarez
(Alejandro Álvarez Ayllón)
September 21, 2023, 7:58am
2
Hi,
That is not a false positive, because there is an unused named parameter.
Either remove the name or comment them out, up to you.
#include <stdio.h>
// Option 1: Comment the name
void BirdRun(int /*leg*/, int wing)
{
printf("birds run %d", wing);
}
// Option 2: Remove the name
void DogRun(int leg, int)
{
printf("dogs run %d", leg);
}
typedef void (*Run)(int, int);
int main(int argc, char** argv)
{
Run dog = DogRun;
dog(1, 2);
Run bird = BirdRun;
bird(3, 4);
return 0;
}
Regards,
Alejandro
Hua_Minghu
(Hua Minghu)
September 22, 2023, 3:30am
3
Thanks for reply,I comment the name,but get an error like this “error: parameter name omitted”.
aalvarez
(Alejandro Álvarez Ayllón)
September 22, 2023, 7:34am
5
True, clang emits a warning (I guess you use -Werror
), but gcc does not. The classical approach for C, that I should have mentioned, for unused parameters is to cast them to (void)
. i.e.
void BirdRun(int leg, int wing)
{
(void)leg;
printf("birds run %d", wing);
}