Re: fshort-wchar
Re: fshort-wchar
- Subject: Re: fshort-wchar
- From: Andreas Grosam <email@hidden>
- Date: Mon, 16 Apr 2012 14:05:39 +0200
On Apr 16, 2012, at 10:05 AM, Anders Markussen wrote:
> On Apr 16, 2012, at 3:33 AM, Ron Hunsinger wrote:
>
>> You're missing a level of indirection.
>>
>>> const wchar_t *a=(const wchar_t *)ap, *b=(const wchar_t *)bp;
>> should be
>> const wchar_t *a=*(const wchar_t * const*)ap, *b=*(const wchar_t * const*)bp;
>
> Of course, I was too quick in typing up that, but that doesn't answer my question.
>
> On Apr 16, 2012, at 3:33 AM, Ron Hunsinger wrote:
>
>>> return *a-*b;
>>
>
> Why is this calculation unsigned? I.e. if *a is less than *b, why do I get a positive result? GCC gives the result I want.
65535 seems odd.
Could you please check if the result of the expression *a - *b is "unsigned int" as well when the types of the operators a and b are actually "unsigned short" ?
According C99 conversion rules, if a and b are "unsigned short", the expression should become effectively:
(int)(*a) - (int)(*b)
That is, the value of the expression (in your case) should equal -1.
On the other hand, if you (possibly) had written:
wchar_t result = *a - *b
return result;
Then, the return value should actually equal 65535.
It appears, there is some evilness here ;)
Note: the underlaying type of a wchar_t is "unsigned short" when the flag -fchar_wchar is set.
>
> - Anders
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Xcode-users mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden