3 ms·
std::list (used correctly) is IMHO a great example of why you should write in C++, not in C. Most large C projects I've seen end up with multiple implementatio
by YZF 14y ago
std::list (used correctly) is IMHO a great example of why you should write in C++, not in C.
Most large C projects I've seen end up with multiple implementations of lists. You will have some combination of:
void* for a generic list, performance issues because everything is a function call to another C file which won't get inlined, memory leaks, subtle bugs, thread safety issues because it's often unclear what guarantees the homebrew version provides.
Do you want to spend your time on reinventing the list or on things that provide value?
(Edited for formatting)
- mangamadaiyan 14y agoHrm. Check out sys/queue.h in any BSD (Linux too - though Linux kernel code IIRC uses a different list implementation). You don't necessarily need void * for a generic list, and you most certainly don't have to reinvent the wheel.
- YZF 14y agoqueue.h is an improvement. You still need to somehow know this is in BSD and you'll need to copy it to build on different systems. The thing is that in C, most people do reinvent the wheel, including the person in the original article and as you say, the Linux kernel. That's been my experience. std::list is standard and cleaner IMO.