G
Gof
vaysagekv said:Do you mean
int strcmp_fast(char* s,char* t){
unsigned long* uls=(unsigned long*)s;
unsigned long* ult=(unsigned long*)t;
if(*uls>*ult) return(1);
if(*uls<*ult) return(-1);
else return(strcmp(s,t));
}
Besides obvious misconceptions, pointed by other people in this thread,
I'm sensitive to constness of variables and arguments. By passing pointers
to a function without const qualifiers, you make people think that your
function is going to modify the strings.
I think that it would be better this way (still with errors mentoined
in other posts):
int strcmp_fast(const char *s, const char *t)
{
const unsigned long *uls = (const unsigned long *) s;
const unsigned long *ult = (const unsigned long *) t;
if (*uls > *ult)
return 1;
if (*uls < *ult)
return -1;
return strcmp(s, t);
}