C equivalent of vector

This is a discussion on C equivalent of vector within the C Programming forums, part of the General Programming Boards category; Hey guys,
I've recently started developing PPC software, and found myself quite hampered by the complete lack of the C++ ...

C equivalent of vector

Hey guys,
I've recently started developing PPC software, and found myself quite hampered by the complete lack of the C++ STL (although most other C++ language features are available). As such, I was just wondering what C programmers use instead of std::vector - I do know that linked lists are one alternative, and static arrays can be used to some limited extent, but otherwise does one have to resort to plain 'ol dynamic arrays?

I always have in the past. I wouldn't be surprized if there was some library out there with structs and functions to work with them - but it's probably best if you just go ahead and start getting used to the C style.

I'm fairly certain that the std::vector is implemented using a dynamic array (can someone confirm/deny this?). A chunk of memory is allocated, and it gets used up as more elements are added to the vector. Once you run out of memory, a call to realloc() is made giving you room to add more elements. A linked list is better than a dynamic array if your vector has massive memory requirements. The reason is that a dynamic array requires contiguous memory whereas the linked list nodes can be allocated from random areas off the heap. Of course with a linked list implementation, you can never do random access in the form of V[x].

>>I wouldn't be surprized if there was some library out there with structs and functions to work with them
Right, but then I suppose it would pretty much be just a 3rd-party, less-friendly std::vector.

I'm asking this simply because I've heard that C and C++ have different ways of doing things, and I figured there might be a better alternative for scalable data structures supporting random access than dynamic arrays (from what I've heard, they're to be avoided wherever possible in C++).

Hey -- I got yelled at yesterday for mentioning c++ on this C board -- and you made the same misstake?

Its not that c arrays don't work well in c++ -- they work just as well in c++ as they do in C. But its because std::vector relieves you of all the work of maintaining the allocation and reallocation of the arrays. std::vector is really not much more than a c++ wrapper for the C arrays.

Its not really all that hard to role your own version of std::vector if you just want the basics -- you could probably write one in just a few hours. WinCE doesn't support console operations, so you don't need to write output operators for fstream or iostream (neither of which are supported either).

C lacks any useful features for producing type-safe generic containers.
A std::vector does not use realloc but generally a placement-new since realloc does not properly destruct/construct objects.
std::vector works due to templates which produce code for each set of types you give the template. But the code to a vector is fairly straightforward and simple, anyone could write it.
In short, if containers are an important aspect of your application, is C really offering you useful tools for accomplishing your goal? If you miss C++ and STL so much, what is stopping you from using them?