somebody dropped a (warning) bomb
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 8 lines · Sergei Organov
Quoted 2 lines · Linus Torvalds
Exactly because "char" *by*definition* is "indeterminate sign" as far as something like "
strlen()" is concerned.Thanks, I now understand that you either don't see the difference between "indeterminate" and "implementation-defined" in this context or consider it non-essential, so I think I've got your point.
If you don't code for a specific compiler with specific settings, there is no implementation defining the signedness of char, and each part of the code using char* will be wrong unless it handles both cases correctly.
Therefore it's either always wrong to call your char* function with char*, unsigned char* _and_ signed char unless you can guarantee not to overflow any of them, or it's always correct to call char* functions with any kind of these.
Off cause if you happen to code for specific compiler settings, one signedness of char will become real and one warning will be legit. And if pigs fly, they should wear googles to protect their eyes ...
Quoted 3 lines
Quoted 1 line
THE FACT IS, THAT "
strlen()" IS DEFINED UNIVERSALLY AS TAKING "char *".So just don't pass it "unsigned char*". End of story.
Using signed chars for strings is wrong in most countries on earth. It was wrong when the first IBM PC came out in 1981, and creating a compiler in 1987 defaulting to signed char is a sure sign of originating from an isolated country and knowing nothing about this planet. Using signed chars in comparisons is especially wrong, and casting each char to unsigned before comparing them is likely to be forgotten. Unsigned character strings are useless because there is no such thing as char(-23), and if these strings weren't casted to signed inside all IO functions, they wouldn't work correctly. Only because many programmers don't compare chars, most programs will work outside the USA. I repeat: Thanks to using signed chars, the programs only work /by/ /accident/! Promoting the use of signed char strings is promoting bugs and endangering the stability of all our systems. You should stop this bullshit now, instead of increasing the pile.
Quoted 7 lines
Quoted 4 lines
That BY DEFINITION means that "
strlen()" cannot care about the sign, because the sign IS NOT DEFINED UNIVERSALLY!And if you cannot accept that fact, it's your problem. Not mine.
I never had problems either with
strlen()or with this warning, so was curious why does the warning is such a problem for the kernel.
The warning is a problem because either it clutters your build log hiding real bugs, you typecast hiding errors whenever a char* function is called, or you disable it globally hiding real signedness bugs. Either way you take it, it's wrong.
Signature · 4 lines
Funny quotes: 12. He who laughs last thinks slowest. Friß, Spammer: [email protected] [email protected]
Quoted 2 lines · Bodo Eggert
Quoted 1 line · Sergei Organov
Linus Torvalds <[email protected]> writes:
[...]
Quoted 4 lines
Using signed chars for strings is wrong in most countries on earth. It was wrong when the first IBM PC came out in 1981, and creating a compiler in 1987 defaulting to signed char is a sure sign of originating from an isolated country and knowing nothing about this planet.
Maybe I'm wrong, but wasn't it the case that C had no "signed char" type that time, so "char" had to be abused for the "tiny signed integer"?
Quoted 3 lines
Using signed chars in comparisons is especially wrong, and casting each char to unsigned before comparing them is likely to be forgotten.
If we start talking about the C language, my opinion is that it's C problem that it allows numeric comparison of "char" variables at all. If one actually needs to compare alphabetic characters numerically, he should first cast to required integer type.
Quoted 3 lines
Unsigned character strings are useless because there is no such thing as char(-23), and if these strings weren't casted to signed inside all IO functions, they wouldn't work correctly.
Didn't you swap "signed" and "unsigned" by mistake in this phrase? Or are you indeed think that using "unsigned char*" for strings is useless?
Quoted 2 lines
Only because many programmers don't compare chars, most programs will work outside the USA.
Comparison of characters being numeric is not a very good property of the C language.
Quoted 4 lines
I repeat: Thanks to using signed chars, the programs only
work /by/ /accident/! Promoting the use of signed char strings is promoting bugs and endangering the stability of all our systems. You should stop this bullshit now, instead of increasing the pile.
Where did you see I promoted using of "singed char strings"?! If you don't like the fact that in C language characters are "char", strings are "char*", and the sign of char is implementation-defined, please argue with the C committee, not with me.
Or use -funsigned-char to get dialect of C that fits your requirements better.
-- Sergei.
Bodo Eggert
NAKQuoted 4 lines · Sergei Organov
Quoted 2 lines · Bodo Eggert
Quoted 1 line · Sergei Organov
Linus Torvalds <[email protected]> writes:
Quoted 8 lines
[...]
Quoted 4 lines
Using signed chars for strings is wrong in most countries on earth. It was wrong when the first IBM PC came out in 1981, and creating a compiler in 1987 defaulting to signed char is a sure sign of originating from an isolated country and knowing nothing about this planet.
Maybe I'm wrong, but wasn't it the case that C had no "signed char" type that time, so "char" had to be abused for the "tiny signed integer"?
Mentioning tha availability of unsigned char was a change in K&R's book "The C programming Language" from 1987 to 1988:
"For some time, type unsigned char has been available. The standard introduces the signed keyword to make signedness explicit for char and other integral objects."
So if there was no "signed char" before, the blame passes on to those who didn't introduce it alongside "unsigned char".
Quoted 8 lines
Quoted 3 lines
Using signed chars in comparisons is especially wrong, and casting each char to unsigned before comparing them is likely to be forgotten.
If we start talking about the C language, my opinion is that it's C problem that it allows numeric comparison of "char" variables at all. If one actually needs to compare alphabetic characters numerically, he should first cast to required integer type.
Char values are indexes in a character set. Taking the difference of indexes is legal. Other languages have ord('x'), but it's only an expensive typecast (byte('x') does exactly the same thing).
Quoted 6 lines
Quoted 3 lines
Unsigned character strings are useless because there is no such thing as char(-23), and if these strings weren't casted to signed inside all IO functions, they wouldn't work correctly.
Didn't you swap "signed" and "unsigned" by mistake in this phrase? Or are you indeed think that using "unsigned char*" for strings is useless?
ACK
Quoted 5 lines
Quoted 2 lines
Only because many programmers don't compare chars, most programs will work outside the USA.
Comparison of characters being numeric is not a very good property of the C language.
NACK, as above
Quoted 6 lines
Quoted 4 lines
I repeat: Thanks to using signed chars, the programs only
work /by/ /accident/! Promoting the use of signed char strings is promoting bugs and endangering the stability of all our systems. You should stop this bullshit now, instead of increasing the pile.Where did you see I promoted using of "singed char strings"?!
char strings are often signed char strings, only using unsigned char prevents this in a portable way. If you care about ordinal values of your strings, use unsigned.
Quoted 7 lines
If you
don't like the fact that in C language characters are "char", strings are "char*", and the sign of char is implementation-defined, please argue with the C committee, not with me.Or use -funsigned-char to get dialect of C that fits your requirements better.
If you restrict yourself to a specific C compiler, you are doomed, and that's not a good start.
Signature · 3 lines
What about those red balls they have on car aerials so you can spot your car in a park. I think all cars should have them! -- Homer Simpson
Quoted 5 lines · Bodo Eggert
Quoted 3 lines · Sergei Organov
Quoted 2 lines · Bodo Eggert
Quoted 1 line · Sergei Organov
Linus Torvalds <[email protected]> writes:
[...]
Quoted 8 lines
Quoted 4 lines
If we start talking about the C language, my opinion is that it's C problem that it allows numeric comparison of "char" variables at all. If one actually needs to compare alphabetic characters numerically, he should first cast to required integer type.
Char values are indexes in a character set. Taking the difference of indexes is legal. Other languages have ord('x'), but it's only an expensive typecast (byte('x') does exactly the same thing).
Why this typecast should be expensive? Is
char c1, c2;
...
if((unsigned char)c1 < (unsigned char)c2)
any more expensive than if(c1 < c2)?
[...]
Quoted 4 lines
Quoted 2 lines
Comparison of characters being numeric is not a very good property of the C language.
NACK, as above
The point was not to entirely disable it or to make it any more expensive, but to somehow force programmer to be explicit that he indeed needs numeric comparison of characters' indexes. Well, I do realize that the above is not in the C "spirit" that is to allow implicit conversions almost everywhere.
Quoted 10 lines
Quoted 6 lines
Quoted 4 lines
I repeat: Thanks to using signed chars, the programs only
work /by/ /accident/! Promoting the use of signed char strings is promoting bugs and endangering the stability of all our systems. You should stop this bullshit now, instead of increasing the pile.Where did you see I promoted using of "singed char strings"?!
char strings are often signed char strings, only using unsigned char prevents this in a portable way. If you care about ordinal values of your strings, use unsigned.
It means that (as I don't want to change the type of my strings/characters in case I suddenly start to care about ordinal values of the characters) I must always use "unsigned char" for storing characters in practice. Right?
There are at least three problems then:
1. The type of "abc" remains "char*", so effectively I'll have two different representations of strings.
2. I can't mix two different representations of strings in C without compromising type safety. In C, the type for characters is "char", that by definition is different type than "unsigned char".
3. As I now represent characters by unsigned tiny integers, I loose distinct type for unsigned tiny integers. Effectively this brings me back in time to the old days when C didn't have distinct type for signed tiny integers.
Therefore, your "solution" to one problem creates a bunch of others. Worse yet, you in fact don't solve initial problem of comparing strings. Take, for example, KOI8-R encoding. Comparing characters from this encoding using "unsigned char" representation of character indexes makes no more sense than comparing "signed char" representations, as both comparisons will bring meaningless results, due to the fact that the order of (some of) the characters in the table doesn't match their alphabetical order.
Quoted 9 lines
Quoted 6 lines
If you don't like the fact that in C language characters are "char", strings are "char*", and the sign of char is implementation-defined, please argue with the C committee, not with me.
Or use -funsigned-char to get dialect of C that fits your requirements better.
If you restrict yourself to a specific C compiler, you are doomed, and that's not a good start.
Isn't it you who insists that "char" should always be unsigned? It's your problem then to use compiler that understands those imaginary language that meets the requirement.
-- Sergei.
Quoted 6 lines · Bodo Eggert
Quoted 5 lines · Sergei Organov
Quoted 2 lines · Linus Torvalds
Exactly because "char" *by*definition* is "indeterminate sign" as far as something like "
strlen()" is concerned.
Quoted 7 lines
Quoted 3 lines
Thanks, I now understand that you either don't see the difference between "indeterminate" and "implementation-defined" in this context or consider it non-essential, so I think I've got your point.
If you don't code for a specific compiler with specific settings, there is no implementation defining the signedness of char, and each part of the code using char* will be wrong unless it handles both cases correctly.
The problem here is that due to historical reasons, there could be code out there that abuses "char" for "signed char" (not sure about "unsigned char"). Old code and old habits are rather persistent.
Quoted 4 lines
Therefore it's either always wrong to call your char* function with char*, unsigned char* _and_ signed char unless you can guarantee not to overflow any of them, or it's always correct to call char* functions with any kind of these.
How are you sure those who wrote foo(char*) agrees with your opinion or even understands all the involved issues?
Quoted 3 lines
Off cause if you happen to code for specific compiler settings, one signedness of char will become real and one warning will be legit. And if pigs fly, they should wear googles to protect their eyes ...
And if people were writing perfect portable code all the time, there would be no need for warnings in the first place...
-- Sergei.
Quoted 11 lines · Sergei Organov
Quoted 6 lines · Bodo Eggert
Quoted 1 line · Sergei Organov
Linus Torvalds <[email protected]> writes:
If you don't code for a specific compiler with specific settings, there is no implementation defining the signedness of char, and each part of the code using char* will be wrong unless it handles both cases correctly.
The problem here is that due to historical reasons, there could be code out there that abuses "char" for "signed char" (not sure about "unsigned char"). Old code and old habits are rather persistent.
There could be code using trigraphs ... and gcc has an option for that.
If this code uses signed chars, using it on unsigned-char-archs is broken and should be warned about, but the compiler will not warn about this because this code will not use "signed char" and therefore it's bug-to-bug syntax compatible, waiting for a semantic breakdown.
I'll say it again: Either the code using unspecified chars is correct, or it isn't. If it's correct, neither using with signed nor with unsigned chars is a bug and you should not warn at all, and if it's not correct, you should always warn. Instead, gcc warns on "code compiles for $arch".
Quoted 7 lines
Quoted 4 lines
Therefore it's either always wrong to call your char* function with char*, unsigned char* _and_ signed char unless you can guarantee not to overflow any of them, or it's always correct to call char* functions with any kind of these.
How are you sure those who wrote
foo(char*)agrees with your opinion or even understands all the involved issues?
Let's asume we have this piece of buggy code. We compile it on an unsigned char architecture. No warning. *BOOM*
Let's asume there is correct code, and we use it as designed:
Warning: Wrong arch
Warning: Wrong arch
Warning: Wrong arch
Warning: real issue
Warning: Wrong arch
Warning: Wrong arch
Warning: Wrong arch
Warning: Wrong arch
<scroll off screen/>
Warning: Wrong arch
Warning: Wrong arch
Warning: Wrong arch
Warning: Wrong arch
Warning: Wrong arch
You don't see "real issue". *BOOM*
What can you do about this warning? Let's asume we cast everywhere:
struct foo * p;
printf(strlen(char*)p); *BOOM*
Let's asume we disable this warning:
int f(unsigned short x)
{
if (!x)
return 0;
return (int) x + f(x-1);
}f(-1); *BOOM*
Therefore unless you program for one arch with one set of compiler flags, this warning is useless, and I did not see much code explicitely designed to be non-portable.
Warning on wrong signedness is good, but if you can't enable it on portable code, it's useless.
Signature · 3 lines
Funny quotes:
39. Ever wonder about those people who spend $2.00 apiece on those little
bottles of Evian water? Try spelling Evian backwards: NAIVEQuoted 1 line · Bodo Eggert
On Fri, 16 Feb 2007, Sergei Organov wrote:
[...]
Quoted 5 lines
I'll say it again: Either the code using unspecified chars is correct, or it isn't. If it's correct, neither using with signed nor with unsigned chars is a bug and you should not warn at all, and if it's not correct, you should always warn. Instead, gcc warns on "code compiles for $arch".
Here is where we disagree. In my opinion, no matter what the sign of char for given architecture is, it's incorrect to pass either "signed char*" or "unsigned char*" argument to a function expecting "char*".
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines
Therefore it's either always wrong to call your char* function with char*, unsigned char* _and_ signed char unless you can guarantee not to overflow any of them, or it's always correct to call char* functions with any kind of these.
How are you sure those who wrote
foo(char*)agrees with your opinion or even understands all the involved issues?Let's asume we have this piece of buggy code. We compile it on an unsigned char architecture. No warning. *BOOM*
There should be warning, -- that's my point. "char" is different. "char" is distinct from either "signed char" or "unsigned char". Always. At least it's how C is defined.
Quoted 16 lines
Let's asume there is correct code, and we use it as designed:
Warning: Wrong arch
Warning: Wrong arch
Warning: Wrong arch
Warning: real issue
Warning: Wrong arch
Warning: Wrong arch
Warning: Wrong arch
Warning: Wrong arch
<scroll off screen/>
Warning: Wrong arch
Warning: Wrong arch
Warning: Wrong arch
Warning: Wrong arch
Warning: Wrong arch
Quoted 4 lines
You don't see "real issue". *BOOM*
What can you do about this warning? Let's asume we cast everywhere:
I already gave an answer in response to Linus:
static inline size_t ustrlen(const unsigned char *s)
{
return strlen((const char *)s);
}Quoted 3 lines
struct foo * p;
printf(strlen(char*)p); *BOOM*
printf(ustrlen(p)); *NO BOOM*
unsigned char* u;
printf(ustrlen(u)); *NO WARNING*
-- Sergei.