4 ms·
Apart from "use the right tool for the job", I always did wonder how C programmers cope without the STL containers: std::vector, std::list, std::set, std::map e
by AshleysBrain 15y ago
Apart from "use the right tool for the job", I always did wonder how C programmers cope without the STL containers: std::vector, std::list, std::set, std::map etc.
Sometimes I need to map a string to a list of numbers. std::map<std::string, std::vector<int> >. Done. All memory allocation taken care of for you as well - nothing to leak. In C, how do you get by? You either have to reinvent a red-black tree each time you want that, or use some kind of type-unsafe macro horror, or just not use that data structure.
That seems to be a significant point of the article as well. Any C programmers care to enlighten me on this? Nowadays I couldn't code for long in C without thinking "screw this, I want a vector" and going back to C++.
- edderly 15y agoFair point, but in systems programming where C is used a lot, the 'system' often/usually has the abstract data types you need, or you're in a lower level enough environment that you want your own custom/hardware specific solution. Crude example: http://kernelnewbies.org/FAQ/LinkedLists http://kernelnewbies.org/FAQ/LinkedLists
- Freaky 15y agoIf you don't like macros (which are used quite a lot for this sort of thing - e.g. http://fxr.watson.org/fxr/source/sys/queue.h http://fxr.watson.org/fxr/source/sys/queue.h), void pointers and function pointers go a long way too. Nobody's writing red-black trees from scratch for every project, really.