Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #159241
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: STC - A "Standard Template Containers" library for C, similar to STL |
| Date | 2021-03-08 11:46 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <s24van$q4i$1@dont-email.me> (permalink) |
| References | <f43320d6-4d1c-4c41-b065-9d3b1d1cd32an@googlegroups.com> <s1q8hv$m07$1@dont-email.me> <s1qf4d$3td$1@dont-email.me> <a27c5551-71cf-4c2f-b1d9-abc230f0c8a3n@googlegroups.com> |
On 08/03/2021 09:23, tylo wrote: > torsdag 4. mars 2021 kl. 12:09:10 UTC+1 skrev David Brown: >> I think your library led to interest here, but I suspect that the >> need for a container library in C is a good deal lower than most >> people think. When you hear about such a library - yours or this >> new one - there's an immediate reaction of "that's great - it will >> save a lot of effort, and be useful in all sorts of cases". And yet >> it barely gets used at all. That doesn't mean that such a library >> could not have been used, but that for many reasons, it doesn't get >> used. > > I think there is some truth in this, but not for the reasons you > point out next. > >> People generally use C at a lower level than other languages. If >> you need good string handling, or map types, or variable sized >> vectors, and you want them to be neat and convenient to work with, >> then C is not the language for job. It is the language to >> /implement/ the code to make these work quickly - not the the >> language for /using/ them. >> >> To my mind, if you need these kinds of structures to form such a >> major part of your coding that a generic container library is very >> helpful, then C is unlikely to be the best choice of language to >> use in the first place. >> >> Perhaps I am wrong about that, and there is real potential for >> wider use of such libraries. > > I do think you are wrong about this. I programmed in c++ almost > exclusively for 10 years, but I would have no qualms writing a larger > program in C which fully used this STC library. I would rather say > that a lot of C programmers are quite conservative, but also less > used to work with data structures like this (naturally, as there are > no such things in C). I certainly agree that a lot of C programmers are conservative. C is a good choice for conservative work (and "conservative" is the right attitude for some kinds of programming) - no other general-purpose and efficient language has the kind of long-term stability that C has. > Also, a large portion of C programmers develops > for embedded devices, and have often electronics background rather > than computer science. Often such programs does not even use dynamic > memory. It is accurate to say that a large proportion of embedded devices are programmed in C - I don't know if it is correct to say that a large proportion of C programmers develop for embedded devices. (I'd love to see some statistics on that one.) You are right that small-systems embedded programmers usually try to avoid dynamic memory - I rarely use it, except for network programming where it is difficult to avoid entirely. That applies equally to my embedded C++ programming (and to assembly, in the old days when I used that much more). > >> It is more likely that in your C code, you only need one type of >> map, or one type of queue, and then you make it yourself with the >> balance you want between performance, simplicity, debugability, >> thread safety, etc. > > This is the widespread myth. It is not a myth - people /do/ make their own structures as needed when programming in C. It might not be a good idea, or the most effective use of the programmers' time - that's another matter. > Sure, you can roll you own simple stack, > but once you need something more (linked list, map, set, even just a > dynamic vector), you will likely create something very limiting, and > quite possible buggy code that isn't even as fast as you think. Once > you have elements of strings, you must manage destruction and > lifetime of the objects. The other aspect of this is that you code is > not using standard components, and therefore much harder to read, > maintain and verify correctness of. > There are no standard containers for C - calling your library "standard" does not make it so. If you (or Jacob) gain enough users, developers, maintainers, documenters for your library that it can be called a "de facto" standard and a fair proportion of C programmers were familiar with it, then it becomes "easy to read" and its correctness can be taken as given. But you don't have that. (I realise this is a chicken-and-egg challenge.) If I download your library and use it with my code, it is not easier to read and maintain than my own little list structure that I am trying to replace. It is /harder/ to read, because your library does so much more. It is /harder/ to verify, because I don't know your code, I don't know if it is correct, if it will work with my choice of compiler, flags, target processor, threading system, etc. I don't know if it will work with interrupt functions, with lists in read-only memory, etc. And to find out, I need to look at the code for a dozen different list features that are irrelevant for me but are part of your "standard" list container. /If/ you can get your library into common use, then your arguments hold - until then, the opposite is true. This is the reality of the situation, unfortunate and unfair though it might seem. >>> 2: Code bloat. I haven't tried, but it would be interesting to >>> know the size of a high level macro in terms of code size. Code >>> bloat slows down the machine since it destroys the code cches. >>> Since some people have compiled this, I would like to know how >>> much is the size of an expanded macro for accessing the nth >>> memeber of a list, for instance. >> It might be interesting to compare the two libraries (and C++ with >> the standard library), with a couple of examples - one in which >> there is only one "map" or "queue" type used in the program, and >> one in which there are several types, perhaps used in separately >> compiled units. You could also compare how the application code >> looks for using these different libraries, to see which looks >> clearer, is easier to understand, easier to get right, and harder >> to get wrong. > > Good points. I have done some of this. STC library code is extremely > compact. Only the methods that are used is linked in when you use the > default static linkage. > Static linkage is good if the code is only used within one translation unit (i.e., one C file, unless you are doing something really weird). If you are using the same container structures, or the same functions, in different C files then you will end up with a lot of code bloat. (Whether or not code bloat is an issue depends on the application. But since you mentioned embedded systems, it can certainly be an issue on some small systems.) C does not have a good solution for this. Some C toolchains can be helpful, if you pick the right options, allowing the compiler and linker to cooperate on merging duplicate code sections and eliminated sections that are not actually used. To get better, you need to move to C++, where templates and "inline" give you better control of code duplication.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
STC - A "Standard Template Containers" library for C, similar to STL tylo <tylovset@gmail.com> - 2021-03-03 07:16 -0800
Re: STC - A "Standard Template Containers" library for C, similar to STL Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-03-03 21:36 +0000
Re: STC - A "Standard Template Containers" library for C, similar to STL "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-03-03 20:49 -0800
Re: STC - A "Standard Template Containers" library for C, similar to STL "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-03-03 13:50 -0800
Re: STC - A "Standard Template Containers" library for C, similar to STL "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-03-03 13:56 -0800
Re: STC - A "Standard Template Containers" library for C, similar to STL John Dill <jadill33@gmail.com> - 2021-03-03 14:17 -0800
Re: STC - A "Standard Template Containers" library for C, similar to STL olcott <NoOne@NoWhere.com> - 2021-03-03 16:21 -0600
Re: STC - A "Standard Template Containers" library for C, similar to STL Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-03-03 22:45 +0000
Re: STC - A "Standard Template Containers" library for C, similar to STL olcott <NoOne@NoWhere.com> - 2021-03-03 17:21 -0600
Re: STC - A "Standard Template Containers" library for C, similar to STL John Dill <jadill33@gmail.com> - 2021-03-03 15:05 -0800
Re: STC - A "Standard Template Containers" library for C, similar to STL olcott <NoOne@NoWhere.com> - 2021-03-03 17:28 -0600
Re: STC - A "Standard Template Containers" library for C, similar to STL "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-03-03 20:44 -0800
Re: STC - A "Standard Template Containers" library for C, similar to STL "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-03-03 20:45 -0800
Re: STC - A "Standard Template Containers" library for C, similar to STL jacobnavia <jacob@jacob.remcomp.fr> - 2021-03-04 10:16 +0100
Re: STC - A "Standard Template Containers" library for C, similar to STL David Brown <david.brown@hesbynett.no> - 2021-03-04 12:09 +0100
Re: STC - A "Standard Template Containers" library for C, similar to STL Bart <bc@freeuk.com> - 2021-03-04 12:00 +0000
Re: STC - A "Standard Template Containers" library for C, similar to STL David Brown <david.brown@hesbynett.no> - 2021-03-04 14:15 +0100
Re: STC - A "Standard Template Containers" library for C, similar to STL tylo <tylovset@gmail.com> - 2021-03-07 14:51 -0800
Re: STC - A "Standard Template Containers" library for C, similar to STL Anton Shepelev <anton.txt@g{oogle}mail.com> - 2021-03-04 19:19 +0300
Re: STC - A "Standard Template Containers" library for C, similar to STL Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2021-03-04 11:41 -0800
Re: STC - A "Standard Template Containers" library for C, similar to STL Ian Collins <ian-news@hotmail.com> - 2021-03-05 10:19 +1300
Re: STC - A "Standard Template Containers" library for C, similar to STL tylo <tylovset@gmail.com> - 2021-03-08 00:23 -0800
Re: STC - A "Standard Template Containers" library for C, similar to STL David Brown <david.brown@hesbynett.no> - 2021-03-08 11:46 +0100
Re: STC - A "Standard Template Containers" library for C, similar to STL tylo <tylovset@gmail.com> - 2021-03-08 05:36 -0800
Re: STC - A "Standard Template Containers" library for C, similar to STL David Brown <david.brown@hesbynett.no> - 2021-03-08 15:19 +0100
Re: STC - A "Standard Template Containers" library for C, similar to STL tylo <tylovset@gmail.com> - 2021-03-08 08:23 -0800
Re: STC - A "Standard Template Containers" library for C, similar to STL Manfred <noname@add.invalid> - 2021-03-08 18:53 +0100
Re: STC - A "Standard Template Containers" library for C, similar to STL David Brown <david.brown@hesbynett.no> - 2021-03-08 20:01 +0100
Re: STC - A "Standard Template Containers" library for C, similar to STL Manfred <noname@add.invalid> - 2021-03-09 17:16 +0100
Re: STC - A "Standard Template Containers" library for C, similar to STL David Brown <david.brown@hesbynett.no> - 2021-03-09 17:55 +0100
Re: STC - A "Standard Template Containers" library for C, similar to STL Kaz Kylheku <563-365-8930@kylheku.com> - 2021-03-09 17:19 +0000
Re: STC - A "Standard Template Containers" library for C, similar to STL David Brown <david.brown@hesbynett.no> - 2021-03-09 19:58 +0100
Re: STC - A "Standard Template Containers" library for C, similar to STL Manfred <noname@add.invalid> - 2021-03-09 18:42 +0100
Re: STC - A "Standard Template Containers" library for C, similar to STL "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-03-08 17:41 -0800
Re: STC - A "Standard Template Containers" library for C, similar to STL "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-03-08 17:45 -0800
Re: STC - A "Standard Template Containers" library for C, similar to STL Eli the Bearded <*@eli.users.panix.com> - 2021-03-04 18:46 +0000
Re: STC - A "Standard Template Containers" library for C, similar to STL "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-03-04 23:35 -0800
Re: STC - A "Standard Template Containers" library for C, similar to STL "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-03-08 17:05 -0800
Re: STC - A "Standard Template Containers" library for C, similar to STL "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-03-08 17:18 -0800
Re: STC - A "Standard Template Containers" library for C, similar to STL tylo <tylovset@gmail.com> - 2021-03-16 14:49 -0700
Re: STC - A "Standard Template Containers" library for C, similar to STL Siri Cruise <chine.bleu@yahoo.com> - 2021-03-09 21:25 -0800
csiph-web