Re: [PATCH v2 2/3] configure.ac: define ICONV_OMITS_BOM if necessary
- From
Danh Doan <congdanhqx@gmail.com>
- Date
- Nov 2, 2019, 00:43 UTC
- Message-ID
- <20191102004342.GA17624@danh.dev>
- In-Reply-To
- <20191101165657.GC26219@sigill.intra.peff.net>
On 2019-11-01 12:56:57 -0400, Jeff King wrote:
Show 10 quoted lines
> On Fri, Nov 01, 2019 at 03:25:10PM +0700, Doan Tran Cong Danh wrote: > > + v = (unsigned char)(out[0]) + (unsigned char)(out[1]); > > + return v != 0xfe + 0xff; > > I wondered at first why not just: > > return v[0] != 0xfe || v[1] != 0xff; > > but the answer is that you are catching BOMs of either endianness. We > might at some point need to distinguish the two,
Yes, it's about catching BOM of either endianess. To distinguish between LE and BE, it'll be better to use AC_C_BIGENDIAN instead (it's friendlier for cross-compiling).
Anyway, we couldn't compare out[0] and out[1] with 0xf{e,f} directly because char could be either signed (-2 and -1) or unsigned (0xfe, 0xff). We must cast it to unsigned char (required to be 8 bits by POSIX), then let the integer promotion promote it to int (at least 16 bits).
-- Danh