Back in 2015 when I reimplemented these functions to use an AVL tree, I
was annoyed by the weakness of the typing of these functions. Both tree
nodes and keys are represented by 'void *', meaning that things like the
documentation for these functions are an absolute train wreck.
To make things worse, users of these functions need to cast the return
value of tfind()/tsearch() from 'void *' to 'type_of_key **' in order to
access the key. Technically speaking such casts violate aliasing rules.
I've observed actual breakages as a result of this by enabling features
like LTO.
I've filed a bug report at the Austin Group. Looking through the notes
of the last two meetings, they are actually making some good progress in
this area now. A new type 'posix_tnode' is being added to correspond to
tree nodes. It will still be defined as 'void' for source-level
compatibility, but in the very far future it could be replaced by a
proper structure type containing a key pointer.
Even though the next version of POSIX will only be released years from
now, go ahead and implement it now. It improves the readability of the
code and the documentation.
Austin Group bug report: http://austingroupbugs.net/view.php?id=1011
Note to reviewers: I will only commit this change when the bug in the
Austin group bug tracker is marked as fixed.