向上取整字节对齐

向上取整字节对齐宏实现方法

/**

  • MEM_ALIGNMENT: should be set to the alignment of the CPU
  • 4 byte alignment -> #define MEM_ALIGNMENT 4
  • 2 byte alignment -> #define MEM_ALIGNMENT 2
    */
    #define MEM_ALIGNMENT 1
    #define LWIP_MEM_ALIGN_SIZE(size) (((size) + MEM_ALIGNMENT - 1) & ~(MEM_ALIGNMENT-1))

一个简单的对变量size进行操作的宏, 它的作用是将size向上对MEM_ALIGNMENT取整, 即保证size是内存对齐字节数的整数倍。

你可能感兴趣的:(向上取整字节对齐)