tags:

views:

636

answers:

3
+7  Q: 

C Analog To 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?

A: 

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.

James Curran
@James Curran, I was asking for an _analog_ to the STL. I realize that templates are a C++ feature.
Onorio Catenacci
STL is more than just a container library.
Martin York
I'm aware that STL is more than a container library, which is why I said "The best you could hope for"
James Curran
@Onorio: Templates are at the very essence of the STL. Your question is much like say "I need something like an airplane, but don't worry about the flying part"
James Curran
@James Curran: So maybe he's looking for a car, bus, train or boat.
Michael Burr
@Mike: Then he would need to clarify what non-flying parts of a plane he wants.
James Curran
@James Curran: Am I mistaken in thinking that there were STL-like structures in C# before the introduction of generics into that language? What about Java--didn't that have data structures analogous to STL before they added generics to that language? Why would a C STL be such a conceptual stretch?
Onorio Catenacci
Prior to the introduction of generic, C# has ArrayList and a few like that, basically, "some collection classes which manipulate void* pointers to unknown object." as I said in my answer. But the STL is far more than that. The affect of LINQ's Enumerable class (in .net) begins to approach STL.
James Curran
+9  A: 

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.

More info from wikipedia: http://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/

Dan
+1  A: 

What part of the functionality do you want?

Paul Nathan
Vlion, as I said, I'm mostly asking from curiosity. I don't write C code any more but I was curious if there were something analogous to the STL in C.
Onorio Catenacci
Good remark: you would need replacement for collections, iterators and algorithms.
xtofl