[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: -funsigned-char
From: |
Bruno Haible |
Subject: |
Re: -funsigned-char |
Date: |
Wed, 08 Feb 2023 01:21:43 +0100 |
Bjarni Ingi Gislason wrote:
> > ../../gnulib-tests/test-localeconv.c:53: assertion 'l->frac_digits ==
> > CHAR_MAX' failed
> > FAIL test-localeconv (exit status: 134)
> >
>
> l->frac_digits is 127 and CHAR_MAX is 255.
>
> This is due to the CFLAG "-funsigned-char"
When you connect a libc compiled for one ABI and a program compiled for a
different ABI (that's what -funsigned-char produces), you evidently get
breakage.
> which I always use having
> compiled "less", which produced a lot of warnings without this flag.
The way to fix the problems occurring because a program wants to view
their strings as 'unsigned char *' is
- NOT to use -funsigned-char, as you just have seen,
- NOT to cast pointers from 'char *' to 'unsigned char *' and vice
versa, because ultimately this leads to strict aliasing violations
in some places,
- BUT to cast individual 'char *' elements to 'unsigned char' right
after fetching them from the string. E.g.
if (isalnum ((unsigned char) *p))
Bruno