Skip to content

Commit aacbd05

Browse files
committed
Modified function pointer casting in 'shellsor.cpp' to avoid warnings/errors from clang++.
1 parent 297855f commit aacbd05

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

shellsor.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,23 +163,26 @@ sort can be (and, in glibc, is) implemented just by using the recursive
163163
version. The last "context" parameter is simply ignored on all
164164
architectures of which the author was aware.
165165
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. */
171171

172172
void shellsort( void *base, const size_t n_elements, const size_t elem_size,
173173
int (*compare)(const void *, const void *))
174174
{
175+
void (*p)() = (void (*)())compare;
176+
175177
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);
177179
}
178180
#endif
179181

180182
/* bsearch() doesn't take a 'context' pointer, and therefore can't use
181183
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
183186
184187
https://gnu.googlesource.com/gcc/+/refs/heads/master/libiberty/bsearch_r.c
185188
@@ -236,7 +239,7 @@ void *bsearch_ext( const void *key, const void *base0,
236239
size_t nmemb, const size_t size,
237240
int (*compar)(const void *, const void *), bool *found)
238241
{
239-
void *p = (void *)compar;
242+
void (*p)() = (void (*)())compar;
240243

241244
return( bsearch_ext_r( key, base0, nmemb, size,
242245
(int (*)( const void *, const void *, void *))p,

0 commit comments

Comments
 (0)