c语言字节对齐

来源:互联网 发布:js event.target 编辑:程序博客网 时间:2021/11/29 07:58
#include <stdio.h>//比如按128字节对其#define _ALIGNMENT_ 128#define ALIGNMENT_MASK (_ALIGNMENT_ - 1)#define aligned_OK(m) (((unsigned long)(m) & ALIGNMENT_MASK) == 0)int main(void){    int a = 1, b;    //将a对齐后的结果给b    b = (a + ALIGNMENT_MASK) & ~ALIGNMENT_MASK;    printf("a = %d, b = %d\n", a, b);    //判断a,b是否按128字节对其    if (aligned_OK(a))    {        printf("a aligned\n");    }    if (aligned_OK(b))    {        printf("b aligned\n");    }    return 0;}

0 0
原创粉丝点击