[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: the wchar_t type



Ulrich Drepper writes:

> Check it again.  Int is already used.  At least all Linux 64-bit
> platforms use int.  Otherwise glibc would not work at all.

You are right for alpha-linux, but not for sparc64-linux. The test program
is appended below.

On i386 and all other 32-bit Linux platforms, wint_t is currently
"unsigned int" whereas wchar_t is "long int", which causes confusion with
`printf' and signedness. I'll ask for changing both to be "int" or
"unsigned int".

Markus Kuhn writes:
> If I remember the C standard correctly, wint_t should be a signed type
> that is a superset of wchar_t and includes WEOF.

wint_t should be unchanged by integral promotions (i.e. suitable as an
argument type in K&R C), and include WEOF. Its signedness is not specified.
Neither is the signedness of wchar_t.

glibc contains the following definitions, which assume that wchar_t is
unsigned:

  #define WCHAR_MIN ((wchar_t) 0)
  #define WCHAR_MAX (~WCHAR_MIN)

  #ifndef WEOF
  # define WEOF (0xffffffffu)
  #endif

I'd prefer to have wchar_t and wint_t signed because the test for WEOF
would then be more efficient on 64-bit platforms.

Bob Verbrugge writes:
> You can't just change existing definitions, some people relying on current
> defintions would't be to to happy i suppose ...

Sure I can change change it from "long" to "int". In C, it makes no
difference, and in g++, "wchar_t" is considered a separate type for
overloading purposes.

> In general wchar_t is not considered to be the type to implement UCS2 or 
> UCS4 in

Sure it is. That's what the ISO C amendment 1 is all about, and that's
what glibc will do.

> the size of wchar_t differs too much between compilers.

C9X specifies that wchar_t is at least 16 bits. This is enough for UCS-2.

                  Bruno


============================================================================
#include <stddef.h>

void foo (wint_t x, wchar_t y)
{
/* Warnings on i386 */
#ifdef __cplusplus
  /* C++ */
  printf ("%ld", x); /* warning: long int format, int arg */
  printf ("%ld", y); /* warning: long int format, int arg */
  printf ("%d", x);  /* no warning */
  printf ("%d", y);  /* no warning */
#else
  /* C */
  printf ("%ld", x); /* warning: long int format, int arg */
  printf ("%ld", y); /* no warning */
  printf ("%d", x);  /* no warning */
  printf ("%d", y);  /* warning: int format, wchar_t arg */
#endif
}

                                                     /* i386 alpha sparc64 */
int sizeof_wint_t = sizeof (wint_t);                 /*  4     4      4    */
int signed_wint_t = ((wint_t) (-1) < (wint_t) 0);    /*  0     0      0    */
int sizeof_wchar_t = sizeof (wchar_t);               /*  4     4      8    */
int signed_wchar_t = ((wchar_t) (-1) < (wchar_t) 0); /*  1     0      1    */
=============================================================================
-
Linux-UTF8:   i18n of Linux on all levels
Archive:      http://mail.nl.linux.org/lists/