Live data from Hacker News

Common libraries and data structures for C

github.com

61–70 of 148 posts

Re: Common libraries and data structures for C

#61

I'm not a C developer, nor have I ever been interested in developing with it. From my perspective, it seems like a massive time drain and non-productive use of my time. Just a few points: - Tooling seems all over the place (build system, package management) - Having to roll your own trivial functions / types (tooling may play into this) - Versioning is confusing (C99, C11, ???) The only advantage I see would be in em…

What do you mean by 'time drain'? Do you know how much time it would take you to port your assembly code from x86 to ARM? And then when a new CPU comes out, you've got to rewrite all that assembly code again. Now that's a time drain. You could write your code once in C, and compile it for any CPU at this point. That's massive amount of your time saved. Again, what do you mean by 'time drain'? Do you know how many hum…

What I found is C compiles fast and produces small binaries.

Adding phat pointers, arrays, tagged unions, and closures to C would fix a lot of the current pain points without turning it into the disaster that is C++.

Re: Common libraries and data structures for C

#62
post #54

For people advocating use of C++ instead of C, keep in mind there are several platforms (mostly embedded) that only support C and not C++. Also there are many projects that make use of C only. If C++ is available, I agree one should use it, however that is not always the choice.

Unless we are talking about something like Z80, 6502, PIC, AVR and similar low end CPUs, which hardly full support even C89, all modern CPUs have C++ compilers available. More often than not, it is a matter of not wanting to use C++ than it not being available.

Why do you mention AVR? AVR-GCC has C++ support, that's what made the original Arduino (before they switched to ARM) approachable to beginners.

Re: Common libraries and data structures for C

#63
post #62
post #54

Earlier quoted context omitted.

Unless we are talking about something like Z80, 6502, PIC, AVR and similar low end CPUs, which hardly full support even C89, all modern CPUs have C++ compilers available. More often than not, it is a matter of not wanting to use C++ than it not being available.

Why do you mention AVR? AVR-GCC has C++ support, that's what made the original Arduino (before they switched to ARM) approachable to beginners.

List of typical 8 bit CPUs, and I was thinking only about commercial compilers.

Re: Common libraries and data structures for C

#64
post #54

For people advocating use of C++ instead of C, keep in mind there are several platforms (mostly embedded) that only support C and not C++. Also there are many projects that make use of C only. If C++ is available, I agree one should use it, however that is not always the choice.

Unless we are talking about something like Z80, 6502, PIC, AVR and similar low end CPUs, which hardly full support even C89, all modern CPUs have C++ compilers available. More often than not, it is a matter of not wanting to use C++ than it not being available.

> More often than not, it is a matter of not wanting to use C++ than it not being available.

That's perfectly valid. I reach for C when I need to write fairly small programs. When C does not fill my needs anymore, I don't reach for C++. There are better high-level languages.

C++ is not a replacement for C. When one of the worlds foremost experts on C++ complains that the language is too complex to understand[1], passing on C++ is a reasonable position.

[1] https://steven.brokaw.org/posts/scott-meyers-cant-remember-c...

Re: Common libraries and data structures for C

#65
post #62
post #54

Earlier quoted context omitted.

Unless we are talking about something like Z80, 6502, PIC, AVR and similar low end CPUs, which hardly full support even C89, all modern CPUs have C++ compilers available. More often than not, it is a matter of not wanting to use C++ than it not being available.

Why do you mention AVR? AVR-GCC has C++ support, that's what made the original Arduino (before they switched to ARM) approachable to beginners.

> AVR-GCC has C++ support

It's a very restricted subset of C++ that has almost no advantages over plain C, and some number of disadvantages.

Re: Common libraries and data structures for C

#66

Earlier quoted context omitted.

Embedded devices really opened my eyes to this world. What a fool I was using malloc on my first Arduino project.

Arduino is entirely C++ though

> Arduino is entirely C++ though

No, it's C++ without exceptions (so constructors are useless).

On Arduino you will almost certainly program in a C-with-classes manner; lack of exceptions make almost everything that C++ brings to the table useless[1].

Re: Common libraries and data structures for C

#67
post #52
post #7

Good stuff. void* in itself is great for generics. C does support a templating system, like C++, with a little (reasonable) preprocessor abuse. It gives great cache contiguous results: https://www.github.com/glouw/ctl

I'm confused. It's easy to emulate a set using a map, but how do you emulate a map using a set?

You model the key->value relationship, call it an association, and place associations in the set, where the equality/hash functions are performed on the association key.

Re: Common libraries and data structures for C

#68

The lengths people will go to not use C++ is staggering.

> The lengths people will go to not use C++ is staggering.

Every C thread on every forum always has some C++ proponent jumping in to bemoan that people prefer one of the simplest languages over, literally, the most complex (from a programmer PoV) language in existence.

Is it really such a stretch to believe that people prefer readability and maintainability over expressive power?

The "lengths" in this case is small - a once of cost of a few days to implement vector and string functions gets you most of what most developers need and want.

Re: Common libraries and data structures for C

#69
There'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 ?

Re: Common libraries and data structures for C

#70
post #62

Earlier quoted context omitted.

Why do you mention AVR? AVR-GCC has C++ support, that's what made the original Arduino (before they switched to ARM) approachable to beginners.

> AVR-GCC has C++ support It's a very restricted subset of C++ that has almost no advantages over plain C, and some number of disadvantages.

- templates instead of macros

- constexpr instead of macros

- if constexpr instead of macros

- stronger type checking

- type inference

- strong type enumerations

- namespacing instead of pre-historic naming prefixes

- classes as means to enforce type invariants

I see some advantages.

Post reply on HN