On 5/4/24 11:07 PM, Paul Eggert wrote: >> Since <sys/endian.h> seems resonably portable, > > I assume you mean <endian.h>? There's no <sys/endian.h> on my Ubuntu system.
No, sorry maybe I worded my original email awkwardly. :) I think all of the BSDs have <sys/endian.h> which define: #define LITTLE_ENDIAN 1234 #define BIG_ENDIAN 4321 #define BYTE_ORDER /* One of thsoe macros. */ >From what I can tell, they also had ntohl and friends there. I think that glibc added the be32toh macros and extended that header, while also moving it to <endian.h>. My history might be a bit wrong there. The headers predate me by a few years. :) I was trying to say that a macro sequence like this could do most of the heavy lifting: #if HAVE_ENDIAN_H # include <endian.h> #elif HAVE_SYS_ENDIAN_H # include <sys/endian.h> #endif Since the BSDs and Solaris should define the same stuff in <sys/endian.h>. > Although that's a start, we'll need more of course. Here's what I have so far > for my prototype stdbit.in.h, but it needs more work. This sort of thing used > to be even trickier (see gl_BIGENDIAN and gl_MULTIARCH) but I hope we can > dispense with that complexity nowadays (by using something like the following > complexity instead :-). Looks good to me. You got more of the compiler stuff than I would have. Collin