• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: fshort-wchar
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fshort-wchar


  • Subject: Re: fshort-wchar
  • From: Ron Hunsinger <email@hidden>
  • Date: Sun, 15 Apr 2012 18:33:54 -0700

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;

That is, when qsort wants to compare your items, it passes the addresses of the items, each of which is a pointer to wchar_t. Thus, the nominally void* parameters to compare are pointers to pointers to wchar_t

-Ron Hunsinger


On Apr 13, 2012, at 5:36 AM, Anders Markussen wrote:

> There seems to be a problem in clang with integral promotions on wchar_t with -fshort-wchar.
> Using Xcode 4.2.1 / clang 3.0
>
> #include <stdlib.h>
> #include <stdio.h>
>
> int compare(void const* ap, void const* bp) {
>        const wchar_t *a=(const wchar_t *)ap, *b=(const wchar_t *)bp;
>        while (*a && *b && (*a == *b)) {
>                ++a; ++b;
>        }
>        return *a-*b;
> }
>
> int main() {
>        const wchar_t* fruit[] = { L"apricot",L"banana" };
>        printf("%d %d\n", L'a'-L'b', compare(fruit[0], fruit[1]));
>        qsort(fruit, 2, sizeof(wchar_t*), compare);
> 	// At this point, in clang, the array has been mis-sorted.
>        return 0;
> }
>
>
> $ g++ -Wall -fshort-wchar -o wchar wchar.cpp
> $ ./wchar
> -1 -1
>
> $ clang++ -Wall -fshort-wchar -o wchar wchar.cpp
> wchar.cpp:14:11: warning: conversion specifies type 'int' but the argument has
> type 'wchar_t' [-Wformat]
>        printf("%d %d\n", L'a'-L'b', compare(fruit[0], fruit[1]));
>                ~^        ~~~~~~~~~
> 1 warning generated.
> $ ./wchar
> 65535 65535
>
> Known? Intended? It hurts our transition from llvm-gcc 4.2 to clang.
>
> - Anders Markussen
>
>
> _______________________________________________
> 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

  • Follow-Ups:
    • Re: fshort-wchar
      • From: Anders Markussen <email@hidden>
References: 
 >fshort-wchar (From: Anders Markussen <email@hidden>)

  • Prev by Date: Re: Where does XCode 4.3.2 store account information?
  • Next by Date: Re: fshort-wchar
  • Previous by thread: fshort-wchar
  • Next by thread: Re: fshort-wchar
  • Index(es):
    • Date
    • Thread