> On 27 Apr 2018, at 11:44, Jim Riggs <jim...@riggs.me> wrote: > >> Major quibble: The comparator should take a parameter that receives the >> array element size. Careful implementations will either use that size or >> check that it's the correct size. APR arrays can contain whole >> structures, not just pointers. > > Again, the comparator has to be smart. It should know what it is receiving. > They may be ints, structs, strings, whatever. It can and should cast as > necessary. The void* is just a way of saying "I'm passing you something. You > have to know how to handle it." It may or may not be a pointer. I have > successfully tested it with char* (using strcmp/strcasecmp) as well as int > and char using custom comp callback functions. They all worked as expected.
Though, I now admit that this presumably only works for types where sizeof(<type>) <= sizeof(void*) due to casting, but that seems like a documentation issue, not a technical one. Personally, I haven't seen or worked with many apr_arrays being used with anything other than pointers, not to say there aren't lots of them. (I am the newish guy on the block.) Heck, even if we were to restrict this function to only working with arrays whose elements are pointers, it would still be useful and help remove some code duplication, IMO.