Re:Moving the Linux Kernel to Modern C
by thetic on Thursday February 24, 2022 @05:19PM
(#30461081)
Though C89 does not support declaration of a scoped loop variable like C99 does:
C89 does support declaration of variables at the top of braced blocks whose scope is limited to that block:
[ Parent
| on HN ]
That extra scope is an issue for what they're doing, however. They have a macro called "list_for_each_entry()" which syntactically behaves as if it were a "for(...)" (because it is a "for(...)"). To make the extra scope work with that macro, either the user of the macro would have to end the loop with an unbalanced amount of closing braces (to match an extra opening brace within the macro), or it would require a second macro to be used at the end of the scope. Keep in mind that this macro is used in literally thousands of files within the kernel.
Sure. This may not be a feasible approach for this case. I'm just pointing out alternative approaches to mitigate this kind of scoping problem in C89. Maybe wrap every use of list_for_each_entry in braces?
{
list_for_each_entry(...)
}Then you get dinged by static analysis tools like SonarQube because you introduced a useless scope or increased the "cognitive complexity" to the code and have to explain it to a team leader who might not understand why you did that.
Re:Moving the Linux Kernel to Modern C
by hn_go_brrrrr on Thursday February 24, 2022 @06:44PM
(#30461933)
A team lead who does not understand that does not have the technical chops to be a team lead.
Doesn’t mean they aren’t still your team lead though!
Re:Moving the Linux Kernel to Modern C
by staticassertion on Thursday February 24, 2022 @10:05PM
(#30463293)
Should we really be making decisions with people like that in mind?
If they are your team lead, would you have a choice?