开发者

How could one emulate namespace in C?

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.


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);


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)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜