Hi! I'm worried about some proposal going on in the C Committee at the moment, and which I've also received for the manual pages.
Some people would like manual pages to use retroactive declarations of
parameters. I fear that would cause all kinds of bugs if programmers
see that syntax and believe it's valid and has the intuitive meaning,
but then compile it and get behavior that might not be what they want.
In particular, I'm worried that this might happen rather often in the
near future:
alx@debian:~/tmp$ cat param.c
int
main(void)
{
int n = 42;
int f(char a[n], int n)
{
return _Countof(a);
}
char s[] = "foo";
return f(s, _Countof(s));
}
alx@debian:~/tmp$ /opt/local/gnu/gcc/cap/bin/gcc -Wall -Wextra param.c
param.c: In function āfā:
param.c:6:30: warning: unused parameter ānā [-Wunused-parameter]
6 | int f(char a[n], int n)
| ~~~~^
alx@debian:~/tmp$ ./a.out; echo $?
42
I would be interested in having a new subflag
-Wshadow=retroactive-parameter, which triggers when a parameter is
shadowing a previous variable and that variable has been used previously
in the same parameter declaration list in which the shadowing parameter
is being declared (but before the shadowing occurs).
This should be part of -Wextra (at least), as it's rather dangerous, and
shouldn't break any existing code (if it triggers, the code is likely
bad).
This would remove my concerns about it.
Have a lovely night!
Alex
--
<https://www.alejandro-colomar.es>
signature.asc
Description: PGP signature
