C 模拟转 STL

发布于 2024-07-07 09:47:50 字数 156 浏览 6 评论 0 原文

只是因为我很好奇——C++ 中是否有与 STL 功能类似的 C 语言? 我见过提到一个名为 glib 的 GTK+ 库,一些人认为它满足了要求,但是还有其他库吗?会在 C 中提供 STL 功能吗?

Just because I'm curious--is there any C analog to the functionality of the STL in C++? I've seen mention of a GTK+ library called glib that a few people consider fills the bill but are there other libraries that would provide STL functionality in C?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

っ左 2024-07-14 09:47:50

是的,glib 是一个非常好的选择:它包含许多用于操作容器的实用程序,如链表、数组、哈希表等。还有一个名为 GObject 的面向对象框架,您可以使用 C 语言创建带有信号和槽的对象(尽管使用相当冗长的函数调用名称,例如 gobject_set_property,因为 C 没有任何对象语法)。 还有主循环的代码,因此您可以编写事件驱动的程序。

有关详细信息,请参阅维基百科:https://en.wikipedia.org/wiki/GLib

Glib最初是 GTK 的一部分,但非 GUI 代码已被完全分解,以便您可以在命令行程序中使用它: http://library.gnome.org/devel/glib/stable/

Yes, glib is a pretty good choice: it includes a lot of utilities for manipulating containers like linked lists, arrays, hash tables, etc. And there is also an object-oriented framework called GObject that you can use to make objects with signals and slots in C (albeit with rather verbose function call names like gobject_set_property, since C doesn't have any syntax for objects). And there is also code for main loops so you can write event-driven programs.

For more info see wikipedia: https://en.wikipedia.org/wiki/GLib

Glib was originally part of GTK, but the non-GUI code has been completely factored out so that you can use it in command-line programs: http://library.gnome.org/devel/glib/stable/

一绘本一梦想 2024-07-14 09:47:50

添加另一个选项(完全公开,我是作者); 如果您可以编译和链接 C++,您可以查看 libcdada,它具有纯 C API,但使用 libstdc++ 作为大多数容器的后端:

< a href="https://github.com/msune/libcdada" rel="nofollow noreferrer">https://github.com/msune/libcdada

Adding another option (full disclosure, I am the author); if you can compile and link C++, you can have a look into libcdada, which has a pure C API, but uses libstdc++ as a backend for most of the containers:

https://github.com/msune/libcdada

笙痞 2024-07-14 09:47:50

好吧,由于 STL 的本质是基于 C 所没有的模板,因此很难接近 C 中的 STL。您最好希望的是一些集合类,它们操纵指向未知对象的 void* 指针。

Well since STL's very nature is based on templates which C doesn't have, it would be difficult to even come close to the STL in C. The best you could hope for is some collection classes which manipulate void* pointers to unknown object.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文