4 ms·
Linus Torvalds once quipped (in a discussion over Git) that "even if the choice of C over C++ had no other benefits than keeping the C++ programmers out, that i
by semi-extrinsic 12y ago
Linus Torvalds once quipped (in a discussion over Git) that "even if the choice of C over C++ had no other benefits than keeping the C++ programmers out, that in itself would be a huge reason to prefer C".
- jjoonathan 12y agoWhat is the preferred way to implement generic containers in C?
- scintill76 12y agoI'm not an expert, but I was curious too and looked around. Apparently glib is pretty popular, and they just use void* (typedef'd to gpointer) for the type of items in the container: https://developer.gnome.org/glib/2.42/glib-Doubly-Linked-Lists.html#g-list-append https://developer.gnome.org/glib/2.42/glib-Doubly-Linked-Lis...
- mcguire 12y agoThere isn't. You don't do generic containers in C; you implement each specific data structure from the ground up to do specifically what you need. This is both a strength and a weakness.
- marktangotango 12y agoThis is a banal question, flame bait at that.
- nitrogen 12y agoYou can write the containers as a ".x" file, which is just C with all of the type names replaced by a macro name. Then you #include the .x file where needed, #define the type before, then #undef it after. Token pasting in the C preprocessor makes for unique names, so multiple container types can be used in the same namespace.
- CountSessine 12y agoYou don't. Go to the standards committee on bended knee and ask for another awkward addition to the language like <complex.h>.
- CountSessine 12y agoJesus, this mess just never ends. Torvalds' criticism of C++ is lazy thinking, but the schadenfreude that non-C++ developers exult in from his criticism is just plain dumb. Go back and read Torvalds' screed (here's a link http://harmful.cat-v.org/software/c++/linus http://harmful.cat-v.org/software/c++/linus). Aside from some sloppy hand-wavy arguments about how he feels icky 'trusting' standard libraries, is he actually criticizing C++? Where in that mess of half-congealed reasoning is mention of multiple-inheritance or operator overloading, or any of the other classic C++ mis-features? Torvalds is a systems-programmer and he detests the greedy-method design-as-we-implement approach to development that C++ application programmers wanted to bring to git. But, guess what? That pretty much describes application developers working in every development language in common use today. You program in Java? Chances are Torvalds thinks you're a hack unworthy of working on git or linux. Ruby? Probably even worse. Javascript? Don't make me laugh. Torvalds even refers to you - yes, you - as "some CS people".