Function prototypes don't need to be declared
extern in .h files. It's assumed by the compiler
and is as unnecessary as using auto is when
declaring automatic/local variables in a block.
I ran a script to remove these unnecessary extern
uses from function prototypes in include/net/ as
well as reflow the function arguments to 80 cols.
It's 370KB, far too large to submit at once.
Of course it could be broken into multiple patches
for the various directories/subsystems.
I believe it makes grepping for extern useful as
all the matches are actual variables and structs.
Thoughts?
---
include/net/act_api.h | 60 ++--
include/net/addrconf.h | 151 +++++-----
include/net/af_rxrpc.h | 35 ++-
include/net/af_unix.h | 16 +-
include/net/arp.h | 30 +-
include/net/ax25.h | 215 +++++++-------
include/net/bluetooth/bluetooth.h | 16 +-
include/net/bluetooth/hci_core.h | 20 +-
include/net/bluetooth/rfcomm.h | 4 +-
include/net/caif/caif_hsi.h | 2 +-
include/net/cfg80211.h | 34 +--
include/net/checksum.h | 10 +-
include/net/cls_cgroup.h | 2 +-
include/net/compat.h | 48 ++--
include/net/dcbevent.h | 6 +-
include/net/dn.h | 20 +-
include/net/dn_dev.h | 30 +-
include/net/dn_fib.h | 46 ++-
include/net/dn_neigh.h | 12 +-
include/net/dn_nsp.h | 49 ++--
include/net/dn_route.h | 13 +-
include/net/dst.h | 22 +-
include/net/esp.h | 2 +-
include/net/fib_rules.h | 19 +-
include/net/flow.h | 10 +-
include/net/flow_keys.h | 2 +-
include/net/garp.h | 28 +-
include/net/gen_stats.h | 52 ++--
include/net/genetlink.h | 20 +-
include/net/icmp.h | 10 +-
include/net/inet6_connection_sock.h | 33 ++-
include/net/inet6_hashtables.h | 40 +--
include/net/inet_common.h | 38 +--
include/net/inet_connection_sock.h | 80 +++---
include/net/inet_hashtables.h | 70 ++---
include/net/inet_sock.h | 4 +-
include/net/inet_timewait_sock.h | 38 +--
include/net/inetpeer.h | 10 +-
include/net/ip.h | 141 ++++-----
include/net/ip6_fib.h | 50 ++--
include/net/ip6_route.h | 93 +++---
include/net/ip_fib.h | 58 ++--
include/net/ip_vs.h | 212 +++++++-------
include/net/ipv6.h | 277 +++++++++---------
include/net/ipx.h | 12 +-
include/net/irda/ircomm_tty.h | 14 +-
include/net/irda/irda.h | 22 +-
include/net/irda/irlap_event.h | 2 +-
include/net/irda/irlap_frame.h | 4 +-
include/net/iw_handler.h | 38 +--
include/net/lapb.h | 52 ++--
include/net/llc.h | 50 ++--
include/net/llc_c_ac.h | 190 ++++++-------
include/net/llc_c_ev.h | 240 ++++++++--------
include/net/llc_conn.h | 38 +--
include/net/llc_if.h | 8 +-
include/net/llc_pdu.h | 30 +-
include/net/llc_s_ac.h | 20 +-
include/net/llc_s_ev.h | 20 +-
include/net/llc_sap.h | 26 +-
include/net/mac80211.h | 10 +-
include/net/mrp.h | 28 +-
include/net/ndisc.h | 56 ++--
include/net/neighbour.h | 98 ++++---
include/net/net_namespace.h | 26 +-
include/net/netevent.h | 6 +-
include/net/netfilter/ipv4/nf_conntrack_ipv4.h | 6 +-
include/net/netfilter/ipv4/nf_defrag_ipv4.h | 2 +-
include/net/netfilter/ipv6/nf_defrag_ipv6.h | 10 +-
include/net/netfilter/nf_conntrack.h | 56 ++--
include/net/netfilter/nf_conntrack_acct.h | 8 +-
include/net/netfilter/nf_conntrack_core.h | 32 +--
include/net/netfilter/nf_conntrack_ecache.h | 25 +-
include/net/netfilter/nf_conntrack_extend.h | 2 +-
include/net/netfilter/nf_conntrack_helper.h | 32 ++-
include/net/netfilter/nf_conntrack_l3proto.h | 16 +-
include/net/netfilter/nf_conntrack_l4proto.h | 24 +-
include/net/netfilter/nf_conntrack_timeout.h | 8 +-
include/net/netfilter/nf_conntrack_timestamp.h | 8 +-
include/net/netfilter/nf_nat.h | 10 +-
include/net/netfilter/nf_nat_core.h | 10 +-
include/net/netfilter/nf_nat_helper.h | 62 ++--
include/net/netfilter/nf_nat_l3proto.h | 26 +-
include/net/netfilter/nf_nat_l4proto.h | 31 +-
include/net/netfilter/nf_queue.h | 2 +-
include/net/netfilter/xt_rateest.h | 4 +-
include/net/netlink.h | 64 ++---
include/net/netprio_cgroup.h | 2 +-
include/net/netrom.h | 90 +++---
include/net/p8022.h | 6 +-
include/net/ping.h | 9 -
include/net/pkt_cls.h | 36 +--
include/net/pkt_sched.h | 40 +--
include/net/protocol.h | 24 +-
include/net/psnap.h | 2 +-
include/net/raw.h | 6 +-
include/net/rawv6.h | 4 +-
include/net/request_sock.h | 12 +-
include/net/rose.h | 113 ++++----
include/net/route.h | 46 +--
include/net/rtnetlink.h | 40 +--
include/net/sch_generic.h | 51 ++--
include/net/scm.h | 10 +-
include/net/sctp/sctp.h | 14 +-
include/net/secure_seq.h | 26 +-
include/net/snmp.h | 2 +-
include/net/sock.h | 240 ++++++++--------
include/net/stp.h | 4 +-
include/net/tcp.h | 380 ++++++++++++-------------
include/net/udp.h | 88 +++---
include/net/udplite.h | 4 +-
include/net/wext.h | 16 +-
include/net/wimax.h | 32 +--
include/net/x25.h | 141 ++++-----
include/net/xfrm.h | 334 +++++++++++-----------
115 files changed, 2636 insertions(+), 2692 deletions(-)
On Tue, 23 Jul 2013 at 17:58 GMT, Joe Perches <[email protected]> wrote:
> Function prototypes don't need to be declared
> extern in .h files. It's assumed by the compiler
> and is as unnecessary as using auto is when
> declaring automatic/local variables in a block.
>
Since we all know this, why bother it? Having "extern" doesn't harm
readability, instead it probably helps.
...
>
> I believe it makes grepping for extern useful as
> all the matches are actual variables and structs.
>
You need a semantic tool.
On Thu, 2013-07-25 at 01:27 +0000, Cong Wang wrote:
> On Tue, 23 Jul 2013 at 17:58 GMT, Joe Perches <[email protected]> wrote:
You dropped the author from the cc list.
Always reply to the author.
> > Function prototypes don't need to be declared
> > extern in .h files. It's assumed by the compiler
> > and is as unnecessary as using auto is when
> > declaring automatic/local variables in a block.
> >
> Since we all know this, why bother it?
If everyone knew this, new ones wouldn't be added.
But a lot are.
Removing extern makes prototypes shorter and more readable.
More prototypes fit in a single line
More arguments fit on a multi-line prototypes.
> Having "extern" doesn't harm
> readability, instead it probably helps.
Sure, just like auto does. Why isn't that used?
> > I believe it makes grepping for extern useful as
> > all the matches are actual variables and structs.
> You need a semantic tool.
No, not really. I'm fairly comfortable with spatch.
spatch takes a long time to run for a lot of things.
On Wed, Jul 24, 2013 at 06:41:20PM -0700, Joe Perches wrote:
> On Thu, 2013-07-25 at 01:27 +0000, Cong Wang wrote:
> > On Tue, 23 Jul 2013 at 17:58 GMT, Joe Perches <[email protected]> wrote:
>
> You dropped the author from the cc list.
> Always reply to the author.
>
> > > Function prototypes don't need to be declared
> > > extern in .h files. It's assumed by the compiler
> > > and is as unnecessary as using auto is when
> > > declaring automatic/local variables in a block.
> > >
> > Since we all know this, why bother it?
>
> If everyone knew this, new ones wouldn't be added.
> But a lot are.
Couldn't checkpatch take care of these?
Greetings,
Hannes
Using the extern keyword on function prototypes is superfluous
visual noise so suggest removing it.
Using extern can cause unnecessary line wrapping at 80 columns
and unnecessarily long multi-line function prototypes.
Suggested-by: Hannes Frederic Sowa <[email protected]>
Signed-off-by: Joe Perches <[email protected]>
---
On Thu, 2013-07-25 at 03:47 +0200, Hannes Frederic Sowa wrote:
> On Wed, Jul 24, 2013 at 06:41:20PM -0700, Joe Perches wrote:
> > On Thu, 2013-07-25 at 01:27 +0000, Cong Wang wrote:
> > > On Tue, 23 Jul 2013 at 17:58 GMT, Joe Perches <[email protected]> wrote:
> > > > Function prototypes don't need to be declared
> > > > extern in .h files. It's assumed by the compiler
> > > > and is as unnecessary as using auto is when
> > > > declaring automatic/local variables in a block.
> > > Since we all know this, why bother it?
> > If everyone knew this, new ones wouldn't be added.
> > But a lot are.
> Couldn't checkpatch take care of these?
checkpatch doesn't work well for multiple lines so
this doesn't work on things like
extern unsigned long
foo(type bar);
but it does for the single line function prototypes.
Using --fix removes them.
scripts/checkpatch.pl | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 6918517..23126d4 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3866,6 +3866,16 @@ sub process {
}
}
+# check for new externs in .h files.
+ if ($realfile =~ /\.h$/ &&
+ $line =~ /^\+\s*(extern\s+)$Type\s*$Ident\s*\(/s) {
+ if (WARN("AVOID_EXTERNS",
+ "extern prototypes should be avoided in .h files\n" . $herecurr) &&
+ $fix) {
+ $fixed[$linenr - 1] =~ s/(.*)\bextern\b\s*(.*)/$1$2/;
+ }
+ }
+
# check for new externs in .c files.
if ($realfile =~ /\.c$/ && defined $stat &&
$stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s)
--
1.8.1.2.459.gbcd45b4.dirty
From: Joe Perches <[email protected]>
Date: Tue, 23 Jul 2013 10:58:11 -0700
> Function prototypes don't need to be declared
> extern in .h files. It's assumed by the compiler
> and is as unnecessary as using auto is when
> declaring automatic/local variables in a block.
>
> I ran a script to remove these unnecessary extern
> uses from function prototypes in include/net/ as
> well as reflow the function arguments to 80 cols.
>
> It's 370KB, far too large to submit at once.
>
> Of course it could be broken into multiple patches
> for the various directories/subsystems.
No objections from me.
Please submit a small number at a time so that my already overflowing
backlog isn't overwhelmed even more.
Thanks.
Hi Joe,
On Tue, 30 Jul 2013 00:10:01 -0700 (PDT) David Miller <[email protected]> wrote:
>
> From: Joe Perches <[email protected]>
> Date: Tue, 23 Jul 2013 10:58:11 -0700
>
> > Function prototypes don't need to be declared
> > extern in .h files. It's assumed by the compiler
> > and is as unnecessary as using auto is when
> > declaring automatic/local variables in a block.
> >
> > I ran a script to remove these unnecessary extern
> > uses from function prototypes in include/net/ as
> > well as reflow the function arguments to 80 cols.
> >
> > It's 370KB, far too large to submit at once.
> >
> > Of course it could be broken into multiple patches
> > for the various directories/subsystems.
>
> No objections from me.
I must admit I prefer the other way (i.e. with the explicit extern). If
nothing else it makes it consistent with variable declarations in header
files (which need the extern) and "static inlines" ...
Making these churn changes also will almost certainly cause unnecessary
conflicts :-(
--
Cheers,
Stephen Rothwell [email protected]
From: Stephen Rothwell <[email protected]>
Date: Tue, 30 Jul 2013 17:38:00 +1000
> I must admit I prefer the other way (i.e. with the explicit extern). If
> nothing else it makes it consistent with variable declarations in header
> files (which need the extern) and "static inlines" ...
>
> Making these churn changes also will almost certainly cause unnecessary
> conflicts :-(
Regardless of preferences, the whole tree is a mix, and we should choose
one way or the other consistently.
It seems like new code in other major subsystems are using the
no-extern scheme, and I'm more than happy to follow suit.
Joe Perches <[email protected]> wrote:
> Using the extern keyword on function prototypes is superfluous
> visual noise so suggest removing it.
>
> Using extern can cause unnecessary line wrapping at 80 columns
> and unnecessarily long multi-line function prototypes.
>
> Suggested-by: Hannes Frederic Sowa <[email protected]>
> Signed-off-by: Joe Perches <[email protected]>
Nak.
The "extern" makes it much easier to pick out at a glance.
Please standardise on there _being_ externs if you must do this.
It's gratuitous change anyway and not worth the churn.
David
On 08/01/2013 02:21 PM, David Howells wrote:
> Joe Perches <[email protected]> wrote:
>
>> Using the extern keyword on function prototypes is superfluous
>> visual noise so suggest removing it.
>>
>> Using extern can cause unnecessary line wrapping at 80 columns
>> and unnecessarily long multi-line function prototypes.
>>
>> Suggested-by: Hannes Frederic Sowa <[email protected]>
>> Signed-off-by: Joe Perches <[email protected]>
>
> Nak.
>
> The "extern" makes it much easier to pick out at a glance.
Really? Grouping function prototypes within the header file is much more
helpful for spotting them.
Regards,
Arend
> Please standardise on there _being_ externs if you must do this.
>
> It's gratuitous change anyway and not worth the churn.
>
> David
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>