3 ms·
FWIW personally i prefer the C code. It is explicit at what it does, whereas the C++ one is harder to follow exactly what it does - and also very ugly (i never
by badsectoracula 7y ago
FWIW personally i prefer the C code. It is explicit at what it does, whereas the C++ one is harder to follow exactly what it does - and also very ugly (i never liked C++'s iterators).
The double indirect pointer is hairy but at least everything you need to know to "parse" the code is right there.
- AnimalMuppet 7y agoIt depends on what you want. If you want to be able to see everything, then the C++ code is better. If you want to get the trees out of the way so that you can see the forest, the C++ code is better. And, for most of us, if you want to just write it and have it work, the C++ code is better. Sure, I might have to find an example of the iterator code in order to get the syntax right, but it's a lot easier to mess up the double indirect pointer code. Worse, when I mess up the iterator code, it likely doesn't compile. If I mess up the double indirect pointer code, it it likely to silently corrupt memory somewhere.
- jcelerier 7y ago> The double indirect pointer is hairy but at least everything you need to know to "parse" the code is right there. but why do you want to spend time parsing code that - does textbook-level things ? - has a thousand different places where a typo can end up - needs to be rewritten for every kind of list those are the red flags. Do you also go read your graphics driver's code when you push pixels to the screen ? > and also very ugly (i never liked C++'s iterators). ignoring the jump from what you like to a global assertion (the C version makes my eyes bleed), in C++ 20 you can also just do list.insert(std::lower_bound(list, val), val);