LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Sergei Organov <osv@javad.com>
To: Bodo Eggert <7eggert@gmx.de>
Cc: "Linus Torvalds" <torvalds@linux-foundation.org>,
	"J.A. MagallÃÃón" <jamagallon@ono.com>,
	"Jan Engelhardt" <jengelh@linux01.gwdg.de>,
	"Jeff Garzik" <jeff@garzik.org>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
	"Andrew Morton" <akpm@linux-foundation.org>
Subject: Re: somebody dropped a (warning) bomb
Date: Mon, 19 Feb 2007 14:56:26 +0300	[thread overview]
Message-ID: <87tzxigy39.fsf@javad.com> (raw)
In-Reply-To: <Pine.LNX.4.58.0702161505460.2481@be1.lrz>

Bodo Eggert <7eggert@gmx.de> writes:
> On Fri, 16 Feb 2007, Sergei Organov wrote:
>> Bodo Eggert <7eggert@gmx.de> writes:
>> > Sergei Organov <osv@javad.com> wrote:
>> >> Linus Torvalds <torvalds@linux-foundation.org> writes:
>
[...]
>> 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)?

[...]

>> 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.

>> > 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.

>> 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.

  reply	other threads:[~2007-02-19 11:56 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <7Mj5f-3oz-21@gated-at.bofh.it>
     [not found] ` <7MktH-5EW-35@gated-at.bofh.it>
     [not found]   ` <7Mmvy-vj-17@gated-at.bofh.it>
     [not found]     ` <7MnBC-2fk-13@gated-at.bofh.it>
     [not found]       ` <7MoQx-4p8-11@gated-at.bofh.it>
     [not found]         ` <7MpjE-50z-7@gated-at.bofh.it>
     [not found]           ` <7MpCS-5Fe-9@gated-at.bofh.it>
     [not found]             ` <7MDd7-17w-1@gated-at.bofh.it>
     [not found]               ` <7MGkB-62k-31@gated-at.bofh.it>
     [not found]                 ` <7NHoe-2Mb-37@gated-at.bofh.it>
     [not found]                   ` <7NMe9-1ZN-7@gated-at.bofh.it>
     [not found]                     ` <7Oagl-6bO-1@gated-at.bofh.it>
     [not found]                       ` <7ObvW-89N-23@gated-at.bofh.it>
     [not found]                         ` <7Oc8t-NS-1@gated-at.bofh.it>
2007-02-15 20:08                           ` Bodo Eggert
2007-02-16 11:21                             ` Sergei Organov
2007-02-16 14:51                               ` Bodo Eggert
2007-02-19 11:56                                 ` Sergei Organov [this message]
2007-02-16 12:46                             ` Sergei Organov
2007-02-16 17:40                               ` Bodo Eggert
2007-02-19 12:17                                 ` Sergei Organov
2007-02-08 15:00 Jeff Garzik
2007-02-08 16:33 ` Linus Torvalds
2007-02-08 18:42   ` Jan Engelhardt
2007-02-08 19:53     ` Linus Torvalds
2007-02-08 21:10       ` Jan Engelhardt
2007-02-08 21:37         ` Linus Torvalds
2007-02-08 23:12           ` David Rientjes
2007-02-08 23:37             ` Linus Torvalds
2007-02-09  0:24               ` David Rientjes
2007-02-09  0:42                 ` Linus Torvalds
2007-02-09  0:59                   ` Linus Torvalds
2007-02-09  0:59                   ` David Rientjes
2007-02-09  1:11                     ` Linus Torvalds
2007-02-09  1:18                       ` David Rientjes
2007-02-09 15:38                         ` Linus Torvalds
2007-02-09  3:27                   ` D. Hazelton
2007-02-09 19:54                     ` Pete Zaitcev
2007-02-09 12:34                   ` Jan Engelhardt
2007-02-09 13:16                     ` linux-os (Dick Johnson)
2007-02-09 17:45                       ` Jan Engelhardt
2007-02-09 20:29                         ` linux-os (Dick Johnson)
2007-02-09 22:05                           ` Jan Engelhardt
2007-02-09 22:58                             ` Martin Mares
2007-02-12 18:50                             ` linux-os (Dick Johnson)
2007-02-13 15:14                     ` Dick Streefland
2007-02-08 21:13       ` J.A. Magallón
2007-02-08 21:42         ` Linus Torvalds
2007-02-08 22:03           ` Linus Torvalds
2007-02-08 22:19             ` Willy Tarreau
2007-02-09  0:03             ` J.A. Magallón
2007-02-09  0:22               ` Linus Torvalds
2007-02-09 12:38             ` Sergei Organov
2007-02-09 15:58               ` Linus Torvalds
2007-02-12 11:12                 ` Sergei Organov
2007-02-12 16:26                   ` Linus Torvalds
2007-02-13 18:06                     ` Sergei Organov
2007-02-13 18:26                       ` Pekka Enberg
2007-02-13 19:14                         ` Sergei Organov
2007-02-13 19:43                           ` Pekka Enberg
2007-02-13 20:29                             ` Sergei Organov
2007-02-13 21:31                               ` Jeff Garzik
2007-02-13 23:21                               ` Linus Torvalds
2007-02-15 13:20                                 ` Sergei Organov
2007-02-15 15:57                                   ` Linus Torvalds
2007-02-15 18:53                                     ` Sergei Organov
2007-02-15 19:02                                       ` Linus Torvalds
2007-02-16  4:26                                         ` Rene Herman
2007-02-19 11:58                                           ` Sergei Organov
2007-02-19 13:58                                         ` Sergei Organov
2007-02-15 22:32                                     ` Lennart Sorensen
2007-02-13 19:25                       ` Linus Torvalds
2007-02-13 19:59                         ` Sergei Organov
2007-02-13 20:24                           ` Linus Torvalds
2007-02-15 15:15                             ` Sergei Organov
2007-02-13 21:13                         ` Rob Landley
2007-02-13 22:21                       ` Olivier Galibert
2007-02-14 12:52                         ` Sergei Organov
2007-02-15 20:06                         ` Sergei Organov
2007-02-09 15:10     ` Sergei Organov
2007-02-08 16:35 ` Kumar Gala

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tzxigy39.fsf@javad.com \
    --to=osv@javad.com \
    --cc=7eggert@gmx.de \
    --cc=akpm@linux-foundation.org \
    --cc=jamagallon@ono.com \
    --cc=jeff@garzik.org \
    --cc=jengelh@linux01.gwdg.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --subject='Re: somebody dropped a (warning) bomb' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).