tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: style(5) proposal: forbid extern in .c



Am 15.03.2023 um 16:40 schrieb Jason Thorpe:

On Mar 15, 2023, at 4:23 AM, Taylor R Campbell <campbell+netbsd-tech-userlevel%mumble.net@localhost> wrote:

Proposal: Forbid extern declarations in .c files.

extern declarations in .c files invite easily avoided bugs where the
definition and use have mismatched types, because the compiler doesn't
have an opportunity to check them.  Fix: Always put the extern
declaration in a .h file shared by the .c file defining it and the .c
files using it.

Pretty simple.  Any objections?

LGTM.  Would be nice if there was a way to get the compiler to enforce this.

I implemented this check as a lint warning, for both objects and functions.

Building NetBSD/amd64 results in 5054 new warnings, which makes this
warning the second-most popular, right between the 11193 'conversion may
lose accuracy' and the 4974 'argument unused in function'.

Roland


Home | Main Index | Thread Index | Old Index