C 语言标准集合在哪里?
我现在致力于学习 C,我擅长 Python/PHP/Bash,但我决定我不能流利地使用 C。但是我无法想象在没有列表和哈希的语言中工作,也许我'我只是有点操之过急,但肯定有“标准”集合库。我在 GNU 标准库中没有看到任何内容,有什么建议吗?
I have committed to learning C now, I'm good with Python/PHP/Bash but I've decided I'm limited by not being fluent in C. However I cannot imagine working in a language without lists and hashes, maybe I'm just jumping a gun, but surely there are 'standard' collection libraries. I do not see any in the GNU standard lib though, any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
C 没有一套“标准”的集合类。许多人只是根据需要推出自己的集合类。
但当然,有一些库填补了这一空白。例如,glib 提供链表、哈希表和各种树。
There is no "standard" set of collection classes for C. Many people simply roll their own as needed.
But of course, there are some libraries filling this gap. For example, glib offers linked lists, hashtables and various kinds of trees.
C 的级别比您习惯的要低。 C 语言中除了数组之外没有标准集合。
C is lower level than you're used to. There are no standard collections in C outside of the array.
没有标准,但有一个很好的替代方案,比 glib 简单得多:Dave Hanson 的 C 接口和实现。它包括几个有效的集合抽象和许多其他有用的模块。该软件是免费的,这本书值得购买。
There is no standard, but there is a superb alternative that is far simpler than glib: Dave Hanson's C Interfaces and Implementations. It includes several efficient collection abstractions and a number of other useful modules. The software is free, and the book is worth buying.
也许你应该尝试研究一下glib。虽然它不是与 C++ STL 相同意义上的标准,但它是一个经过验证的库,并且在许多应用程序中使用。
http://library.gnome.org/devel/glib/2.22/
Maybe you should try looking into glib. While it's not a standard in the same sense as STL for C++ it's a proven library and is used in a lot of applications.
http://library.gnome.org/devel/glib/2.22/
根据您的系统,您可能会在 sys/queue.h,其中包括“单链表、双链表、简单队列和尾队列的实现”。
Depending on your system, you may find what you're looking for in sys/queue.h, which includes "implementations of singly-linked lists, doubly-linked lists, simple queues, and tail queues".
cdcontainers接口类似于C++ STL
https://github.com/maksimandrianov/cdcontainers
The cdcontainers interface is similar to C ++ STL
https://github.com/maksimandrianov/cdcontainers
C 中没有真正的标准集合。作为一种非常低级的语言(与 C++ 和更“现代”的语言相比),
C++ 通过 标准模板库。大多数“集合”(例如散列和列表)都基于 C 中不可用的面向对象或通用编程技术(除了通过约定)。
There aren't really standard collections in C. Being a very low-level language (compared to C++ and more "modern" languages)
C++ adds these via the Standard Template Library. Most of the "collections" such as hashing and lists are based on object oriented or generic programming techniques unavailable (other than via convention) in C.
不存在“标准”(作为 ISO C 标准的一部分)容器库,至少从 C99 开始是这样。我见过一些第三方的尝试;全部都有某种程度的损失或其他。
C有一个非常原始和贫乏的工具包;我将 C 语言编程比作只用手锯和羊角锤建造一座房子。
There are no "standard" (as in part of the ISO C standard) container libraries, at least not as of C99. I've seen several third-party attempts; all had some degree of lossage or another.
C has a very primitive and meager toolkit; I've compared programming in C to building a house with nothing but a handsaw and a claw hammer.