Skip to contentSkip to conversation

util: Add 'static' attribute to function implementation

PATCH Applied Stefan Weil 3 participants 5 messages Mar 16, 2014 – Mar 17, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 util: Add 'static' attribute to function implementation

The static code analyzer smatch complains because of a missing 'static' attribute:

util/module.c:166:6: warning:
symbol 'module_load' was not declared. Should it be static?

'static' is used in the forward declaration, but not in the implementation. Add it there, too.

---
 util/module.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
util/module.c +1 -1
index 863a8a3..214effb 100644
@@ -163,7 +163,7 @@ out:
 }
 #endif
 
-void module_load(module_init_type type)
+static void module_load(module_init_type type)
 {
 #ifdef CONFIG_MODULES
     char *fname = NULL;
Signature · 1 line
1.7.10.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Stefan Weil

'static' is used in the forward declaration, but not in the implementation. Add it there, too.

You might consider reporting this as a bug in the analyzer, since the static in the forward declaration does apply to the definition.

That said, for style it's usually better to make them match, so,

r~

#2 lore raw

Am 16.03.2014 19:06, schrieb Richard Henderson:

Quoted 10 lines · Stefan Weil
Quoted 2 lines

'static' is used in the forward declaration, but not in the implementation. Add it there, too.

You might consider reporting this as a bug in the analyzer, since the static in the forward declaration does apply to the definition.

That said, for style it's usually better to make them match, so,

Yes, the forward declaration applies here. IMHO it helps human reviewers if they can see directly that some function is only local, therefore I prefer the attribute 'static' at both code locations.

We have a similar situation with other attributes, too. Smatch also complains about missing QEMU_NORETURN in our implementation code (we add it only in header files for global functions). Do you think it would be good to make header and implementation match there, too?

Stefan

#3 lore raw
Quoted 4 lines · Stefan Weil

We have a similar situation with other attributes, too. Smatch also complains about missing QEMU_NORETURN in our implementation code (we add it only in header files for global functions). Do you think it would be good to make header and implementation match there, too?

Not without changing our CODING_STYLE.

I'm not really fond of

void attributes some_function(arg, arg, arg)

since its quite easy to wind up with too long lines. It's one of the things I really like about the gnu style

void attributes
some_function(arg, arg, arg)

layout. (In addition to being an old codger who really liked to be able to do "grep ^some_function *.c" to find the implementation.)

r~