project-navigation
Personal tools

Author Topic: q_shared.c -- Q_StringSort  (Read 2653 times)

pleiades

  • Guest
q_shared.c -- Q_StringSort
« on: August 30, 2006, 07:32:58 pm »
Code: [Select]
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;
}


edit: code tags

pleiades

  • Guest
only for gcc
« Reply #1 on: September 08, 2006, 04:00:21 pm »
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
--------------------------------------

Offline Bandobras

  • Captain
  • *****
  • Posts: 586
    • View Profile
q_shared.c -- Q_StringSort
« Reply #2 on: September 08, 2006, 09:26:32 pm »
Mattn, wasn't it your code?

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
q_shared.c -- Q_StringSort
« Reply #3 on: September 08, 2006, 09:41:08 pm »
yes - but i don't have vc - please put up a diff for it and i'll commit

LeXa2

  • Guest
q_shared.c -- Q_StringSort
« Reply #4 on: September 10, 2006, 06:02:16 am »
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.