tech-kern archive

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

static functions are your friends (Was GPIO revisited)




On Jul 25, 2009, at 3:53 AM, Marc Balmer wrote:

One more comment...

+int    gpio_pinbyname(struct gpio_softc *, char *gp_name);
+
+/* Old API version */
+int gpio_ioctl_oapi(struct gpio_softc *, u_long cmd, void *data, int flag,
+    int pinset);

KNF: no variables names in the declaration.
Also, any reason why these are not static?

While it certainly can make sense to declare functions static in some userland programs for the sole reason to include a command in a crunched binary, it does not make sense in kernel code; much to the contrary, it makes debugging harder.

static functions make great sense in kernel code. In fact, we have too many public functions as is and even more of the kernel should be using static.

When a component only has a relatively small on entry points, it allows the compiler to treat the component as one single unit to compiled. This allows it to inline, follow the scope of variables, and lots of other thing to generate better code.

The other reason to use static it prevents code from calling your function that should never have never called it in the first place.



Home | Main Index | Thread Index | Old Index