大小端转换的例子

Linux/include/linux/swab.h

#define constant_swab32(x) \
      ((uint32_t)((((uint32_t)(x) & 0x000000FFU) << 24) | \
              (((uint32_t)(x) & 0x0000FF00U) <<  8) | \
              (((uint32_t)(x) & 0x00FF0000U) >>  8) | \
              (((uint32_t)(x) & 0xFF000000U) >> 24)))

#define le32_to_cpu(x) (__builtin_constant_p(x) ? \
                  constant_swab32(x) : \
                  swab32(x))

#define constant_le32_to_cpu(x) constant_swab32((x))

#define cpu_to_le32(x) le32_to_cpu((x))

你可能感兴趣的:(内核-驱动,c技术)