C considered dangerous
C considered dangerous
Posted Aug 30, 2018 11:06 UTC (Thu) by jani (subscriber, #74547)In reply to: C considered dangerous by mina86
Parent article: C considered dangerous
I occasionally do git grep popularity contests across the kernel tree to get a feeling whether the use of some function or construct or style is generally accepted or needs caution. Your suggested git grep leads to 28 matches, of which only 3 are actual kernel code and the rest are tools or scripts. Of about 83k for loops in the kernel tree. Conclusion, don't use it.
Variable declarations inline in code are harder to grep, but the short gut feeling answer is, don't use them either. The declaration in the for loop is more likely to be accepted I think.
> It’s true that predominant style is to declare variables at the start of a function
Not just at the start of a function. Declarations at the start of a block are widely used.
Uniform style serves a purpose too, as it makes the code faster and easier for the human readers to grasp.
