Common libraries and data structures for C
91–100 of 148 posts
Re: Common libraries and data structures for C
#92I don’t understand how after all these years there isn’t a common library that everyone uses for this stuff. There seems to be a bunch of different ones, but not a single standout that most people use. Why not? Where is Boost for C?
Re: Common libraries and data structures for C
#93I think using the cleanup attribute, and a defer macro can make it happen.
Re: Common libraries and data structures for C
#94There's the Clib initiative at https://github.com/clibs . I don't know how much they curate/review their entries. As often said, apt install foo is also a bit of a package manager for C. Maybe we should establish a sort of expert-led central archive of rock-solid, battle-tested C libs/functions/snippets that one can trust ?
Maybe we should establish a sort of expert-led central archive of rock-solid, battle-tested C libs/functions/snippets that one can trust ?
GNUlib [1], albeit marketed as a "portability library", in fact shares a lot of that goal and includes data structure implementation, OS interfaces, etc. A couple of excerpts from the docs:* "Gnulib is intended to be the canonical source for most of the important “portability” and/or common files for GNU projects. These are files intended to be shared at the source level" [3]
* "We develop and maintain a testsuite for Gnulib. The goal is to have a 100% firm interface so that maintainers can feel free to update to the code in git at any time and know that their application will not break." [3]
[1]: https://www.gnu.org/software/gnulib/manual/html_node/index.h...
[2]: https://www.gnu.org/software/gnulib/manual/html_node/Gnulib-...
[3]: https://www.gnu.org/software/gnulib/manual/html_node/High-Qu...
Re: Common libraries and data structures for C
#95Earlier quoted context omitted.
On most embedded systems you cannot include std . You don't have a decent memory allocator. Bad use of templates will consume all of your flash space (code duplication). Yes, it can work for simple Arduino sketches, and I won't say that there are not complex embedded projects in C++. But... why should I want to use C++? For one, I use a small subset, like it's C with classes. I like function overloading and default a…
You cannot also use stdio and most stdlib, so what? You would want to use C++ for stronger type safety, proper enumerations, templates instead of undebuggable macros, namespaces,.... https://news.ycombinator.com/item?id=31406942 "CppCon 2016: Jason Turner “Rich Code for Tiny Computers: A Simple Commodore 64 Game in C++17”" https://www.youtube.com/watch?v=zBkNBP00wJE MCUs also don't support full-blown C, and it isn't…
You can still use a subset of stdio and stdlib. Newlib also provides hooks you can use to implement fopen and the like, if you want.
> better safety options
Safety is not always the utmost priority. At least, not that kind of safety. It seems people forget this concept from time to time.
> templates instead of undebuggable macros
This is if you use complex macros, which is not always the case. I've been doing embedded for 20 years and I rarely (very rarely) find problems with macros.
But you know what's undebuggable on embedded? Complex inheritance, which sooner or later you'll hit with OOP.
For a system in which you don't have a screen, or logs, or any kind of output, that is usually not in your table, and you have to study failures by telling someone to look at an LED, or by guessing what could have gone wrong, you have to keep your system simple.
Add templates to the mix and good luck opening the project six months later, when a customer calls with a problem.
Edit: But again, used with caution, C++ can be used in embedded, at least the way I use it, as explained before.
Re: Common libraries and data structures for C
#96Earlier quoted context omitted.
You cannot also use stdio and most stdlib, so what? You would want to use C++ for stronger type safety, proper enumerations, templates instead of undebuggable macros, namespaces,.... https://news.ycombinator.com/item?id=31406942 "CppCon 2016: Jason Turner “Rich Code for Tiny Computers: A Simple Commodore 64 Game in C++17”" https://www.youtube.com/watch?v=zBkNBP00wJE MCUs also don't support full-blown C, and it isn't…
> You cannot also use stdio and most stdlib, so what? You can still use a subset of stdio and stdlib. Newlib also provides hooks you can use to implement fopen and the like, if you want. > better safety options Safety is not always the utmost priority. At least, not that kind of safety. It seems people forget this concept from time to time. > templates instead of undebuggable macros This is if you use complex macros,…
Yeah, safety and IoT unfortunately aren't something that go together.
Using C++ doesn't require OOP all over the place, nor crazy template metaprogramming.
The same reason you give for using macros.
Re: Common libraries and data structures for C
#97Okay, I love C so of course I had to take a look. The buzzwords are impressive, with all the testing and CI and so on, really nice, modern and ambitious. I dove into the code, literally looking at the first true part of the implementation in array/sc_array.h. Two observations, from probably less than tree minutes of reading: 1. The nomenclature with "sc_array_term()" as the destructor (the opposite of sc_array_init()…
The macro does not look (necessarily) as a bug, it simply does a counter intuitive thing of zeroing everything, including the capacity. Maybe the way it is used, the capacity is saved, then the array cleared, then it is set back; or more likely it is used only after the allocation of the object, when everything requires to be zeroed (but if this is the case it should be called "_init" and not "_clear", for clarity).…
It might not be an implementation bug, but that is just asking for bugs. Possibly very hard to find bugs.
Re: Common libraries and data structures for C
#98Re: Common libraries and data structures for C
#99The lengths people will go to not use C++ is staggering.
Re: Common libraries and data structures for C
#100I quickly scanned for things that stood out for me. As with anything, there are some things I disagree with.
To wit: the condition variable code includes a mutex inside of it, to deal with the case where you perform a signal on something before there is a waiter. Does this solve some problems? Sure. But it introduces extra overhead when I know what I'm doing and just want a condition variable.
These types of small things - the author thinks this is the "right thing", whereas others won't - are why no C standard C library like this exists. In C, the beauty is that you make every single decision; someone else's decisions won't be the same as yours.