Skip to main content
added 194 characters in body
Source Link
Ivaylo Strandjev
  • 71.4k
  • 18
  • 130
  • 183

This implementation is definitely not optimization of the built-in strcmp, it is simply another implementation and I believe it will most probably perform worse than the built-in version.

A comparison function is supposed to return 0 if the values being compared are equal, any negative number if the first value is smaller and any positive number if the first value is greater. And that is what happens on the last line.

The idea of the last line is to cast the characters to unsigned chars and I believe the author meant for this to sort non-standard characters after the standard ones(ASCII codes 0-127).

EDIT: there is no bug in the code and it can and will return negative values if value pointed to by s1 is smaller than the value pointed to by s2 ordering standard characters before characters with code 128 and above.

This implementation is definitely not optimization of the built-in strcmp, it is simply another implementation and I believe it will most probably perform worse than the built-in version.

The idea of the last line is to cast the characters to unsigned chars and I believe the author meant for this to sort non-standard characters after the standard ones(ASCII codes 0-127).

EDIT: there is no bug in the code and it can and will return negative values if value pointed to by s1 is smaller than the value pointed to by s2 ordering standard characters before characters with code 128 and above.

This implementation is definitely not optimization of the built-in strcmp, it is simply another implementation and I believe it will most probably perform worse than the built-in version.

A comparison function is supposed to return 0 if the values being compared are equal, any negative number if the first value is smaller and any positive number if the first value is greater. And that is what happens on the last line.

The idea of the last line is to cast the characters to unsigned chars and I believe the author meant for this to sort non-standard characters after the standard ones(ASCII codes 0-127).

EDIT: there is no bug in the code and it can and will return negative values if value pointed to by s1 is smaller than the value pointed to by s2 ordering standard characters before characters with code 128 and above.

added 12 characters in body
Source Link
Ivaylo Strandjev
  • 71.4k
  • 18
  • 130
  • 183

This implementation is definitely not optimization of the built-in strcmp, it is simply another implementation and I believe it will most probably perform worse than the built-in version.

The idea of the last line is to cast the characters to unsigned chars and I believe the author meant for this to sort non-standard characters after the standard ones(ASCII codes 0-127). However because of the cast I believe there is a bug

EDIT: there is no bug in thisthe code causingand it to only be able tocan and will return 0 or positivenegative values if value. This will happen because pointed to by s1 is smaller than the difference of two unsignedvalue pointed to by s2 ordering standard characters is never negativebefore characters with code 128 and above.

This implementation is definitely not optimization of the built-in strcmp, it is simply another implementation and I believe it will most probably perform worse than the built-in version.

The idea of the last line is to cast the characters to unsigned chars and I believe the author meant for this to sort non-standard characters after the standard ones(ASCII codes 0-127). However because of the cast I believe there is a bug in this code causing it to only be able to return 0 or positive value. This will happen because the difference of two unsigned characters is never negative.

This implementation is definitely not optimization of the built-in strcmp, it is simply another implementation and I believe it will most probably perform worse than the built-in version.

The idea of the last line is to cast the characters to unsigned chars and I believe the author meant for this to sort non-standard characters after the standard ones(ASCII codes 0-127).

EDIT: there is no bug in the code and it can and will return negative values if value pointed to by s1 is smaller than the value pointed to by s2 ordering standard characters before characters with code 128 and above.

Source Link
Ivaylo Strandjev
  • 71.4k
  • 18
  • 130
  • 183

This implementation is definitely not optimization of the built-in strcmp, it is simply another implementation and I believe it will most probably perform worse than the built-in version.

The idea of the last line is to cast the characters to unsigned chars and I believe the author meant for this to sort non-standard characters after the standard ones(ASCII codes 0-127). However because of the cast I believe there is a bug in this code causing it to only be able to return 0 or positive value. This will happen because the difference of two unsigned characters is never negative.