Technical support > Feature Requests

q_shared.c -- Q_StringSort

(1/1)

pleiades:

--- Code: ---int Q_StringSort(const void *string1, const void *string2)
{
if(*(char *)string1 < *(char *)string2)
return -1;
else if(*(char *)string1 == *(char *)string2) {
while(*(char *)string1) {
string1++; /*error C2036: 'const void *' : unknown size  --->    ((char *)string1)++;   ?  */
string2++; /*error C2036: 'const void *' : unknown size  --->    ((char *)string2)++;  ? */

if(*(char *)string1 < *(char *)string2)
return -1;
else if(*(char *)string1 == *(char *)string2) {
;
} else
return 1;
}
return 0;
} else
return 1;
}
--- End code ---


edit: code tags

pleiades:
string1++; /*error C2036: 'const void *' :
string2++; /*error C2036: 'const void *

from gcc-help@gcc.gnu.org <gcc-help@gcc.gnu.org>

-----------------------------------
GCC supports pointer arithmetic on void * pointers as an
extension.

Try it with -Wall -ansi -pedantic.

> string1++;  //MS VC have got error  size unknown
> string2++;  //MS VC have got error  size unknown

MSVC doesn't have that extension
--------------------------------------

Bandobras:
Mattn, wasn't it your code?

Mattn:
yes - but i don't have vc - please put up a diff for it and i'll commit

LeXa2:
Strange name for a string-comparing function. :))

Why don't you use some standard strings libs, instead of reinventing the wheel again?
Doing str++ on a void pointer certainly won't work on multi-byte characters strings. Also, not for all the codepages character codes order matches the order humans naturally use to sort stings. Good example is KOI8-R charset, for which such a way of comparison would lead to a totally incorrect ordering of russian strings.

Navigation

[0] Message Index

Go to full version