In C99 and above, you can, if you wish, declare variables not only at the top of a function, but throughout the function. This is a feature of other languages too, but is not so prevalent in even recent C.
Programmers working on heavily standardised and safety critical code may find it frustrating that cppcheck does not differentiate between declaring all variables at the top of the function and other variable-scope issues. Personally, I regard it as a readability disaster to, and something that may be against one's coding standard. However, it may well also be against the coding standard to have variables in scopes wider than is required, so I don't want to suppress variableScope failures altogether.
Might it be possible to introduce a suppression switch mechanism purely for these top-of-function declarations, even when the C standard in use allows for mid-function declarations? Something like
With reference to https://sourceforge.net/p/cppcheck/discussion/general/thread/22200d529f/ in which Mr Marjamäki suggests reducing the scope of a variable.
In C99 and above, you can, if you wish, declare variables not only at the top of a function, but throughout the function. This is a feature of other languages too, but is not so prevalent in even recent C.
Programmers working on heavily standardised and safety critical code may find it frustrating that cppcheck does not differentiate between declaring all variables at the top of the function and other variable-scope issues. Personally, I regard it as a readability disaster to, and something that may be against one's coding standard. However, it may well also be against the coding standard to have variables in scopes wider than is required, so I don't want to suppress variableScope failures altogether.
Might it be possible to introduce a suppression switch mechanism purely for these top-of-function declarations, even when the C standard in use allows for mid-function declarations? Something like
To be clear, I would like to write:
And NOT: