In some C projects, function names start with a common prefix indicative of the module name, for example:
mymodule_do_this_stuff();
mymodule_do_that_stuff();
Is there a justification for doing so when the linkage is internal, and there is no possibility of namespace collisions?
For example,
static void mymodule_do_this_stuff(void)
{
...
}
Best Answer
Why prefixes in the first place?
The prefix for function names is a C practice that intends to avoid naming conflicts.
This is especially suitable in big projects, where different teams could easily come with
do_this()
anddo_that()
in different subcomponents of a large codebase.Since C lacks of a
namespace
or apackage
feature, the prefix is the most common workaround. It’s not the only workaround: There are other approaches , but with their own drawbacks.Does it make sense for static functions?
Of course, prefixing internal static functions does not reduce any naming conflict. This is a side effect of the prefix scheme decided in the first place.
The reasons that justifies this practice are:
static
functions were not necessarily static from their inception.static
or notstatic
is something that could change over time. And mixing prefixed and unprefixed name could make such natural changes more painful than necessary.