Re: git: ed52baf51bd1 - main - _endian.h: Include sys/ctypes.h for visibility macros
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 23 Mar 2023 08:13:29 UTC
On Thu, Mar 23, 2023, 8:53 AM Colin Percival <cperciva@tarsnap.com> wrote: > > > On 3/21/23 19:26, Warner Losh wrote: > > [...] > > This had the side effect of sometimes (in the traditional BSD > > compliation environment) > > #if BYTE_ORDER == LITTLE_ENDIAN > > and > > #if BYTE_ORDER == BIG_ENDIAN > > both being true because none of these were defined. This fixes > > that. It also fixes including it after <stdio.h> but not before. > > Would it be worth adding > > #if LITTLE_ENDIAN == BIG_ENDIAN > #error Endian defines are broken! > #endif > > just to ensure that any future issues show up quickly? > Not in *endian.h. The problem is that we fail to define them at all, then user programs expect to use them and sometimes they are defined, and other times they are not. Inside of endian.h the above can be true when we're not compiling for __BSD_VISIBLE because in C's reprocessor, undefined values are substituted with zero always... I'd planned on adding a test for it, though, to make sure that we catch this case in testing. But I was planning on that test being: #include <endian.h> int big_endian = BIG_ENDIAN; int little_endian = LITTLE_ENDIAN; int byte_order = BYTE_ORDER which will catch the undefined case since there's no 'substitute 0 for undefined' in an rval. Warner