Skip to content

Commit 70dc8a4

Browse files
JoePerchestorvalds
authored andcommitted
checkpatch: warn when using extern with function prototypes in .h files
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. Signed-off-by: Joe Perches <joe@perches.com> Suggested-by: Hannes Frederic Sowa <hannes@stressinduktion.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 7e51f19 commit 70dc8a4

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

‎scripts/checkpatch.pl‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3878,6 +3878,16 @@ sub process {
38783878
}
38793879
}
38803880

3881+
# check for new externs in .h files.
3882+
if ($realfile =~ /\.h$/ &&
3883+
$line =~ /^\+\s*(extern\s+)$Type\s*$Ident\s*\(/s) {
3884+
if (WARN("AVOID_EXTERNS",
3885+
"extern prototypes should be avoided in .h files\n" . $herecurr) &&
3886+
$fix) {
3887+
$fixed[$linenr - 1] =~ s/(.*)\bextern\b\s*(.*)/$1$2/;
3888+
}
3889+
}
3890+
38813891
# check for new externs in .c files.
38823892
if ($realfile =~ /\.c$/ && defined $stat &&
38833893
$stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s)

0 commit comments

Comments
 (0)