What are "class[es] built from functions and incomplete types"? I once built classes using structs and function pointers, but this sounds different?
Show HN: C library of generic, reference-counted data structures
31–40 of 42 posts
Re: Show HN: C library of generic, reference-counted data structures
#32Linked library in nice, but how many C projects do you know that use camelCase() function naming as opposed to K&R's lower_case_naming()? If it were a complex library, like OpenSSL, then - sure, to the hell with the notation, just put a wrapper around it and use it anyway. It's barely an issue. But if it is a simpler library that is meant to be weaved into the code, like data containers, the choice of naming notation is always a thing to consider.
There is obviously an indent tool, but resorting to it means using a modified version of the original with all the consequences that follow. Perhaps, it might be the next thing for GitHub to tackle - "Download in Xyz naming notation"... I know I'd use it.
Re: Show HN: C library of generic, reference-counted data structures
#33It's nice that you made these available. You might also want to look at queue.h from BSD (see http://fxr.watson.org/fxr/source/sys/queue.h ) and tree.h ( http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/sys/tree.h ), single-file "libraries" that can generate a few different kinds of linked list and binary tree. These don't require typecasting at all, since they generate functions for your particular type. They are also…
> You might also want to look at queue.h from BSD CPP macros, entirely. No, thanks.
Re: Show HN: C library of generic, reference-counted data structures
#34Earlier quoted context omitted.
> You might also want to look at queue.h from BSD CPP macros, entirely. No, thanks.
Just as an anecdote, in one of my university classes we had the assignment of writing and optimizing a memory allocator. When I switched from using structs to using pointer arithmetic in macros, I gained a significant performance boost, even though the in-memory data was exactly the same.
Re: Show HN: C library of generic, reference-counted data structures
#35Any particular reason why you're avoiding the C99 _Bool?
Re: Show HN: C library of generic, reference-counted data structures
#36Earlier quoted context omitted.
Just as an anecdote, in one of my university classes we had the assignment of writing and optimizing a memory allocator. When I switched from using structs to using pointer arithmetic in macros, I gained a significant performance boost, even though the in-memory data was exactly the same.
were you compiling with optimizations on?
Re: Show HN: C library of generic, reference-counted data structures
#37Was there a rationale to choosing performActionOnStruct() names instead of the perhaps-more-idiomatic struct_perform_action() style? I strongly advise against putting identifiers like release() and getCString() in the global namespace, that's probably not the wisest idea if you plan to use libraries other than your own.
Some bad habits from Java are the only reason. I thought about having obrelease and obgetCString. Putting ob at the beginning of every function seems like overkill, and I don't like that only some functions had would have ob at the beginning if I didn't do a global name change. Any suggestions?
That's "C-style namespaces" - really the only sane way to avoid an identifier collision, sorry.
Re: Show HN: C library of generic, reference-counted data structures
#38It's nice that you made these available. You might also want to look at queue.h from BSD (see http://fxr.watson.org/fxr/source/sys/queue.h ) and tree.h ( http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/sys/tree.h ), single-file "libraries" that can generate a few different kinds of linked list and binary tree. These don't require typecasting at all, since they generate functions for your particular type. They are also…
Intrusive data structures are indeed more powerful. I made my own instrusive AVL-tree which can be found here [1] and an example here [2]. There's also the extra feature that the concept of a "link" is abstracted, so you can for example build a compressed AVL-tree inside an array using array indices instead of pointers, which don't break when the array is reallocated. It's also built in a different way than this usua…
Re: Show HN: C library of generic, reference-counted data structures
#39It's nice that you made these available. You might also want to look at queue.h from BSD (see http://fxr.watson.org/fxr/source/sys/queue.h ) and tree.h ( http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/sys/tree.h ), single-file "libraries" that can generate a few different kinds of linked list and binary tree. These don't require typecasting at all, since they generate functions for your particular type. They are also…
Should you ever need said macros, I've written a set: https://github.com/wrl/wwrl/blob/master/vector.h
Re: Show HN: C library of generic, reference-counted data structures
#40Earlier quoted context omitted.
> You might also want to look at queue.h from BSD CPP macros, entirely. No, thanks.
I'm not a fan of macros either, which is why I've ended up implementing hybrid C data structures, with the logic in functions, and some optional type helpers in macros: https://github.com/pmj/genccont Anyway, these are largely intrusive and don't do reference counting, but that can be seen as an advantage or disadvantage, depending on the situation. (I use these heavily in kernel code) The hash tables (chaining and o…
I don't really understand the fear of macros. void pointers are much scarier than macros, since they open you up to the threat of bugs going undetected by the type system.
You're not by any chance maintaining one of those much-maligned "driver portability" layers, are you?