Junio C Hamano <gits...@pobox.com> writes:

> I wonder if the approach like the following might be cleaner to
> extend as we find other oddball platforms.
>
>     #undef __SHA1DC_BYTE_ORDER
>     #if defined(_BYTE_ORDER)
>     #define __SHA1DC_BYTE_ORDER _BYTE_ORDER
>     #elif defined(__BYTE_ORDER)
>     #define __SHA1DC_BYTE_ORDER __BYTE_ORDER
>     #elif defined(__BYTE_ORDER__))
>     #define __SHA1DC_BYTE_ORDER __BYTE_ORDER__
>     #endif
>
>     #ifdef __SHA1DC_BYTE_ORDER
>      #undef __SHA1DC_BIG_ENDIAN
>      /* do the same for variations of BIG_ENDIAN constant */
>      #if defined(_BIG_ENDIAN)
>       ...
>      #endif
>
>      #if __SHA1DC_BYTE_ORDER == __SHA1DC_BIG_ENDIAN
>      #define SHA1DC_BIGENDIAN
>      #endif
>     #else
>      /* 
>       * as the platform does not use "compare BYTE-ORDER with
>       * BIG_ENDIAN macro" strategy, defined-ness of BIG_ENDIAN
>       * may be usable as a sign that it is a big-endian box.
>       */
>     #endif

IF the above turns out to be a good approach, it may be better to
determine the __SHA1DC_BIG_ENDIAN outside #ifdef __SHA1DC_BYTE_ORDER
block.  That makes the resulting #if/#endif nest shallower; the last
part for platforms that uses defined-ness of BIG_ENDIAN (with
underscore variants) needs to know __SHA1DC_BYTE_ORDER anyway.

So in short, two preparatory blocks followed by the real thing,
something along the lines of...

        #undef __SHA1DC_BYTE_ORDER
        /* set the above from BYTE_ORDER with underscore */

        #undef __SHA1DC_BIG_ENDIAN
        /* set the above from BIG_ENDIAN with underscore */

        #undef SHA1DC_BIGENDIAN
        #if defined(__SHA1DC_BYTE_ORDER)
        # if defined(__SHA1DC_BIG_ENDIAN)
        #  if __SHA1DC_BYTE_ORDER == __SHA1DC_BIG_ENDIAN
        #   define SHA1DC_BIGENDIAN
        #  endif
        # endif
        #else

          /* other heuristics like processor bits here */

        /* 
         * the platform does not compare BYTE-ORDER with BIG-ENDIAN
         * so take the definedness of BIG-ENDIAN as the sign that
         * the box is big endian.
         */
        # if defined(__SHA1DC_BIG_ENDIAN)
        #  define SHA1DC_BIGENDIAN
        # endif
        #endif

Reply via email to