9 ms·
Though C89 does not support declaration of a scoped loop variable like C99 does: for(int i = 0; i < 10; i++) { // ... } C89 does support decla
by thetic 5y ago
Though C89 does not support declaration of a scoped loop variable like C99 does:
for(int i = 0; i < 10; i++) {
// ...
}
C89 does support declaration of variables at the top of braced blocks whose scope is limited to that block:
{
int i;
for(i = 0; i < 10; i++) {
// ...
}
}
- spc476 5y agoThen 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.
- jrockway 5y agoI guess don't use a C99 linter on a C89 codebase?
- hn_go_brrrrr 5y agoA team lead who does not understand that does not have the technical chops to be a team lead.
- lazide 5y agoDoesn’t mean they aren’t still your team lead though!
- staticassertion 5y agoShould we really be making decisions with people like that in mind?
- lazide 5y agoIf they are your team lead, would you have a choice?
- cesarb 5y agoThat 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.
- thetic 5y agoSure. 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(...) }