venj / theunarchiver

Automatically exported from code.google.com/p/theunarchiver
Other
0 stars 0 forks source link

Better endian converting macro #248

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It would be better for converting unsigned long (2G~4G) with gcc.

// CODE FRAGMENT OF ConvertE.c

//#define EndGetM32(a)  (((((unsigned char *) a)[0]) << 24) |             \
#define EndGetM32(a)  ((unsigned long)((((unsigned char *) a)[0]) << 24) |
            \
                       ((((unsigned char *) a)[1]) << 16) |             \
                       ((((unsigned char *) a)[2]) <<  8) |             \
                       ((((unsigned char *) a)[3])))

//#define EndGetI32(a)  (((((unsigned char *) a)[3]) << 24) |             \
#define EndGetI32(a)  ((unsigned long)((((unsigned char *) a)[3]) << 24) |
            \
                       ((((unsigned char *) a)[2]) << 16) |             \
                       ((((unsigned char *) a)[1]) <<  8) |             \
                       ((((unsigned char *) a)[0])))

//#define _convM32(a,n)(((((unsigned char *) a)[n+0]) << 24) |            \
#define _convM32(a,n)((unsigned long)((((unsigned char *) a)[n+0]) << 24) |
           \
                      ((((unsigned char *) a)[n+1]) << 16) |            \
                      ((((unsigned char *) a)[n+2]) <<  8) |            \
                      ((((unsigned char *) a)[n+3])))
//#define _convI32(a,n)(((((unsigned char *) a)[n+3]) << 24) |            \
#define _convI32(a,n)((unsigned long)((((unsigned char *) a)[n+3]) << 24) |
           \
                      ((((unsigned char *) a)[n+2]) << 16) |            \
                      ((((unsigned char *) a)[n+1]) <<  8) |            \
                      ((((unsigned char *) a)[n+0])))

Original issue reported on code.google.com by fujic...@gmail.com on 16 Apr 2010 at 12:48

GoogleCodeExporter commented 9 years ago
This is legacy code from libxad. It is rarely or never used in practice, so 
there is 
little sense is messing with it unless it is actually breaking.

Original comment by paracel...@gmail.com on 16 Apr 2010 at 12:52