This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

why does strstr return a pointer to a signed char?

Sorry for the basic question, but why does it not return a pointer to an unsigned char? I mean, I looked in K&R but it does explain the rational (as far as I could tell...)

Thanks

Parents
  • The only time I can see that it would be a trouble is when comparing two strings. But then again, requiring the C standard to support configurable collation orders would very much affect the speed and size.

    Signed/unsigned does not mean that the string functions are limited to 7-bit ASCII. It is just a question of how the upper 128 characters should be viewed.

    Many compilers has a compilation flag to specify if the default should be signed or unsigned, but I normally never use this flag. It is better to write the code to don't care about the sign of char. After all, we got the two keywords signed and unsigned to allow us to specifically force the required representation when it is important.

Reply
  • The only time I can see that it would be a trouble is when comparing two strings. But then again, requiring the C standard to support configurable collation orders would very much affect the speed and size.

    Signed/unsigned does not mean that the string functions are limited to 7-bit ASCII. It is just a question of how the upper 128 characters should be viewed.

    Many compilers has a compilation flag to specify if the default should be signed or unsigned, but I normally never use this flag. It is better to write the code to don't care about the sign of char. After all, we got the two keywords signed and unsigned to allow us to specifically force the required representation when it is important.

Children