In C++ one might use namespace to keep independent groups working in the same code base from inadvertently creating functions with the same name and thus creating a conflict. My question is, before the idea of namespace comes out, how might one emulate namespace in C.
+16
A:
By naming things differently, e.g.:
void namespace_group_function();
gtk+ is a prime example for this conventional style:
GtkWidget* gtk_window_new(GtkWindowType type);
Georg Fritzsche
2010-03-20 00:34:30
It works for isolating independent groups, but it does not support Argument Dependent Lookup and namespace aliasing.
Matthieu M.
2010-03-20 12:49:25
+2
A:
For symbols not exported you put each module in a separate file.
For exported symbols you generally apply a prefix. Two or three letters are common.
dmckee
2010-03-20 00:35:25
+5
A:
Use a common prefix for the names of all of your public symbols, so foo::bar
becomes foo_bar
. tossing a prefix on all of the symbol names is essentially what namespaces do. (and also resolving symbols used without the prefix to declarations that have the prefix, which is pretty helpful)
John Knoeller
2010-03-20 00:37:03