4 ms·
That's a bad coding style document. There's no rationale given, except for a bunch of references at the top, which are clearly argument from authority. I think
by astrobe_ 2y ago
That's a bad coding style document. There's no rationale given, except for a bunch of references at the top, which are clearly argument from authority.
I think the no "loop initial declarations" is for consistency with "all declarations at the top". Other coding style guides favor "declarations as close as possible to first use", including guidelines for mission critical systems (if you resort to argument from authority I have some too...) [1].
As much as I like Suckless, this section is just pet peeves that can safely be ignored; unless you submit a patch to a project that aligns with it.
[1] https://pvs-studio.com/en/docs/warnings/v2551/ https://pvs-studio.com/en/docs/warnings/v2551/
- flykespice 2y agotheir rationale is very inconsistent: tells you to use c99 but you must place declarations at the top, and you can't use C++ style // comments (introduced in c99 aswell). Why not force c90 altogether then?
- guenthert 2y ago> There's no rationale given True and it would indeed be desirable that it were. Here I go out on a limb and assume it's because someone got bitten by attempting to use the loop index outside the loop (common for search operations) while declaring the index within and outside the loop. A bug (gcc and clang can warn about using -Wshadow, but which sadly isn't part of -Wall) which might easily occur when multiple people edit the code over a longer time-span.
- celrod 2y agoI use Wshadow personally. I highly recommend it. I think code that violates it (even if correct) is harder to understand.