Reputation: 25868
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.
Upvotes: 12
Views: 1011
Reputation: 34148
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)
Upvotes: 7
Reputation: 101181
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.
Upvotes: 2
Reputation: 98974
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);
Upvotes: 18