2.45 Branch Created
Richard Earnshaw (lists)
Richard.Earnshaw@arm.com
Fri Jul 18 14:43:57 GMT 2025
On 18/07/2025 15:30, Maciej W. Rozycki wrote:
> On Wed, 16 Jul 2025, Jan Beulich wrote:
>
>>>> Hmm, does our coding standard permit the use of local variable
>>>> declarations other than at the start of a block now?
>>>
>>> We require C99, so yes.
>>
>> I actually think the two are separate from one another: We could certainly
>> require C99 to use some, but not all of what it permits. Whether to allow
>> declarations in the middle of statements is possibly worth a separate
>> discussion (and I view this distinctly different from having decls in e.g.
>> loop headers, where the variables then still have a pronounced scope).
>
> Exactly my point!
>
> For example glibc has required a C99 compiler since long before us, but
> its coding standard not only allows the use of local variable declarations
> other than at the start of a block, but it actually requires one to place
> such declarations only at the first actual use of a variable, which may be
> well into any block.
>
> Conversely the Linux kernel has also required a C99 compiler for a while
> now, but its coding standard actually forbids the use of local variable
> declarations other than at the start of a block.
>
> GCC and GDB have both long switched to C++ now, but they also have their
> specific requirements beyond what the relevant standards say.
>
> So the requirements are really on a per-project basis and not necessarily
> literally matching any ISO C (or C++) or POSIX standard revision.
>
> Maciej
Any rule like this that can't be enforced by some other tools (eg the compiler or GNU indent) is always going to end up with missed cases. It's even worse when people work on multiple code bases with conflicting rules that have no common ground.
Is there real value to such a rule? If not, then I suggest we don't have one.
R.
More information about the Binutils
mailing list