@@ -163,23 +163,26 @@ sort can be (and, in glibc, is) implemented just by using the recursive
163
163
version. The last "context" parameter is simply ignored on all
164
164
architectures of which the author was aware.
165
165
166
- It seems like an excellent idea. But it's a weird cast that produces a
167
- warning in GCC 8 , and I'm not actually calling the non-recursive sort
168
- anyway; it's completely untested. Hence the above #ifdef to remove both
169
- usused code and the warning. If I someday decide I need a non-recursive
170
- sort, I'll deal with it all then. */
166
+ It seems like an excellent idea. The weird cast is essentially the one
167
+ used for bsearch_ext() (see below) , and I am reasonably confident the
168
+ following would work. However, I've not needed it yet and it is therefore
169
+ untested and #ifdeffed out. If I someday decide I need a non-recursive
170
+ sort, I'll test it then. */
171
171
172
172
void shellsort ( void *base, const size_t n_elements, const size_t elem_size,
173
173
int (*compare)(const void *, const void *))
174
174
{
175
+ void (*p)() = (void (*)())compare;
176
+
175
177
shellsort_r ( base, n_elements, elem_size,
176
- (int (*)(const void *, const void *, void *))compare , NULL );
178
+ (int (*)( const void *, const void *, void *))p , NULL );
177
179
}
178
180
#endif
179
181
180
182
/* bsearch() doesn't take a 'context' pointer, and therefore can't use
181
183
the above sort of re-entrant comparison function. 'bsearch_r()' is
182
- available on some more modern GCCs. Code for bsearch_r() is at
184
+ available on some more modern GCCs (but not older ones and not on
185
+ Microsoft C/C++.) Code for bsearch_r() is at
183
186
184
187
https://gnu.googlesource.com/gcc/+/refs/heads/master/libiberty/bsearch_r.c
185
188
@@ -236,7 +239,7 @@ void *bsearch_ext( const void *key, const void *base0,
236
239
size_t nmemb, const size_t size,
237
240
int (*compar)(const void *, const void *), bool *found)
238
241
{
239
- void *p = (void * )compar;
242
+ void (*p)() = (void (*)() )compar;
240
243
241
244
return ( bsearch_ext_r ( key, base0, nmemb, size,
242
245
(int (*)( const void *, const void *, void *))p,
0 commit comments