unsigned policy (implicit conversions for complex?)
Andrei Alexandrescu (See Website For Email)
SeeWebsiteForEmail at erdani.org
Tue Feb 13 01:27:14 PST 2007
Frits van Bommel wrote:
> Joel C. Salomon wrote:
>> Walter Bright wrote:
>>> Derek Parnell wrote:
>>>> Characters are not numbers.
>>>
>>> That's an enticing point of view, and it sounds good. But Pascal has
>>> that view, and my experience with it is it's one of the reasons
>>> Pascal sucks.
>>>
>>> Examples:
>>>
>>> 1) converting text <=> integers
>>> 2) converting case
>>
>> Neither are pointers numbers, but
>> &a - &b
>> yields a usable number. So long as
>> x += c - 'a'
>> works, I don’t care if
>> 'a' * '3'
>> breaks.
>
> Thank $DEITY. If nobody made this point before I read all of this
> subthread I would have to write a long post explaining this.
>
> Let me reiterate that: characters are to integers as pointers are to
> integers.
> The difference between two pointers is an integer, and you can add
> integers to pointers. These are the only arithmetic operations allowed
> on pointers.
> The same should hold if you substitute 'character' for 'pointer'
> everywhere in previous two sentences.
>
>
> Now, a short comment for each of the cases:
>
> Walter Bright wrote:
> > Examples:
> >
> > 1) converting text <=> integers
>
> I don't see any reason why disallowing conversions from characters to
> integers would disallow one to add or subtract integers from characters.
> So (for c of type char/wchar/dchar) c - '0' can still be an integer, for
> example.
> But it makes absolutely no sense to be able to say c + '0'. Or c * '0'.
>
> > 2) converting case
>
> As above, (c - 'A') + 'a' can still be allowed. (c - 'A') is an integer,
> add 'a' to get a character again.
>
> > 3) doing compression/encryption code
>
> These should probably use void[] for input and ubyte[] for output.
>
> > 4) using characters as indices (isspace() for example)
>
> If you're using Unicode this is a bad idea anyway. Except perhaps if you
> use a sparce associative array, and then this isn't a problem anyway.
>
> If you insist on using a regular array (and make sure the character
> value is suitably small) you don't necessarily have to use a cast, you
> can also subtract '\0' if you prefer.
>
>
> Back to Joel:
>>> 4) using characters as indices (isspace() for example)
>>
>> Is there a way to declare the index type of an array?
>
> Only if you use an associative array.
I think these are great ideas that could help us rethink the whole
character handling business.
Andrei
More information about the Digitalmars-d
mailing list