I don't know this is the right place to ask this,
but let me explain a problem i have today.
I encountered the following compile errors when trying to gmake
httperf, an http benchmark tool.
/usr/include/netinet/tcp.h:54: error: duplicate member `th_off'
/usr/include/netinet/tcp.h:55: error: duplicate member `th_x2'
th_off and th_x2 is defined in netinet/tcp.h like this
---------------------------------------------------------------------
#if BYTE_ORDER == LITTLE_ENDIAN
u_int th_x2:4, /* (unused) */
th_off:4; /* data offset */
#endif
#if BYTE_ORDER == BIG_ENDIAN
u_int th_off:4, /* data offset */
th_x2:4; /* (unused) */
#endif
---------------------------------------------------------------------
After some research, I discovered that BYTE_ORDER and
{BIG,LITTLE}_ENDIAN have no value when copiled with
POSIX or XPG macros.
#if 0 == 0 evaluated as true, which means
BYTE_ORDER == LITTLE_ENDIAN and BIG_ENDIAN are both evaluated as true,
results in both part of code equally processed!
Constant BYTE_ORDER and {BIG,LITTLE}_ENDIAN seem to be not defined
when POSIX/XPG macros is used. see the following.
---------------------------------------------------------------------
sys/cdefs.h
/*
* Finally deal with BSD-specific interfaces that are not covered
* by any standards. We expose these when one of the POSIX or XPG
* macros is defined or if the user explicitly asks for them.
*/
#if !defined(_BSD_SOURCE) && \
(defined(_ANSI_SOURCE) || defined(__XPG_VISIBLE) || defined(__POSIX_VISIBLE))
# define __BSD_VISIBLE 0
#endif
sys/endian.h
#if __BSD_VISIBLE
#define LITTLE_ENDIAN _LITTLE_ENDIAN
#define BIG_ENDIAN _BIG_ENDIAN
#define PDP_ENDIAN _PDP_ENDIAN
#define BYTE_ORDER _BYTE_ORDER
#endif
---------------------------------------------------------------------
Using _BYTE_ORDER and _{BIG,LITTLE}_ENDIAN,
we can fix this problems, however are there any reason
the way to check endian is costructed like this?
I'm very new to BSD so I misunderstand something,
but in my opinion this makes porting work harder.
Any comment appreciated.