4 ms·
> as straightforward as I've seen in C To be fair, the most straightforward definition of the linked list is generic, and C completely lacks such facility. >
by Koshkin 4y ago
> as straightforward as I've seen in C
To be fair, the most straightforward definition of the linked list is generic, and C completely lacks such facility.
> fascist-
Sounds familiar.
https://news.ycombinator.com/item?id=33478321 https://news.ycombinator.com/item?id=33478321
- asveikau 4y ago> C completely lacks such facility. Generic linked lists can be done with pointer casts. See the way the Linux kernel does it. The list manipulation routine takes a pointer to a member, and the more specific type is opaque. The code that knows what the actual structure is can derive it from a node pointer. A structure can even have multiple node pointers in this scheme.
- kazinator 4y agoGeneric facilities can be opinionated. There are various ways to skin the cat, with different tradeoffs. Template mechanisms cause code bloat and encapsulation violations: having to reveal the entire implementation to the clients so they can instantiate it for whatever type they want. Some generic mechanisms have dumb restrictions, like you can make a "list of integer", whose elements, sadly, all have to be integers. In C you can envision what you want genericity to look like at the detailed bit-and-byte memory level, and how you'd like to be able to work with it at the language level, pick some compromises where the two are at odds, and make it happen. It is false to say that C completely lacks any generic facility because it has union types. Using a union we can put several types into a structure along with a type field which indicates which. We can overlay an integer, character, floating-point number, or pointer to something outside of the node.
- imran0 4y ago> Sounds familiar. I cannot decide whether it's an honor or an insult to be called a _fascist sympathizer_ for opposing the authoritarian suppression of speech.
- asveikau 4y agoI didn't want to address this because it's a tangent, but I understand that free speech protects expressing fascist thought. I can still disapprove of it and not want to be around a lot of it, consider high concentrations of it to be a sign of an unhealthy community, without saying it should be somehow illegal.