* [PATCH] checkpatch: Add test for char * arrays that could be static const
@ 2014-02-22 1:18 Joe Perches
0 siblings, 0 replies; only message in thread
From: Joe Perches @ 2014-02-22 1:18 UTC (permalink / raw)
To: Andrew Morton; +Cc: Andy Whitcroft, lkml
static const char* arrays create smaller text as each
function call does not have to populate the array.
Emit a warning when char *arrays aren't static const
and the array is not apparently global by being
declared in the first column.
Signed-off-by: Joe Perches <joe@perches.com>
---
scripts/checkpatch.pl | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 646295c..2e6257b 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2675,6 +2675,13 @@ sub process {
$herecurr);
}
+# check for non-global char *foo[] = {"bar", ...} declarations.
+ if ($line =~ /^.\s+(?:static\s+|const\s+)?char\s+\*\s*\w+\s*\[\s*\]\s*=\s*\{/) {
+ WARN("STATIC_CONST_CHAR_ARRAY",
+ "char * array declaration might be better as static const\n" .
+ $herecurr);
+ }
+
# check for function declarations without arguments like "int foo()"
if ($line =~ /(\b$Type\s+$Ident)\s*\(\s*\)/) {
if (ERROR("FUNCTION_WITHOUT_ARGS",
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2014-02-22 1:18 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-22 1:18 [PATCH] checkpatch: Add test for char * arrays that could be static const Joe Perches
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®