内存对齐

#include "stdio.h"
#include "malloc.h"
typedef struct tagstruct
{
    char a;
    long b;
    short c;
}structm;
int main()
{
    structm *pstruct=NULL;
    pstruct=(structm * )malloc(2*sizeof(structm));
    if (NULL==pstruct)
    {
        return 1;
    }

    pstruct->a=0x11;
    pstruct->b=0x12345678;
    pstruct->c=0x3377;
    pstruct+=1;
    pstruct->a=0x44;
    pstruct->b=0x12345678;
    pstruct->c=0x5588;
    printf("%d",pstruct->a);
    printf("%d",pstruct->b);
    printf("%d",pstruct->c);
    pstruct--;
    free(pstruct);
    return 0;


}

 

posted @ 2013-09-05 22:46  cheshulin  阅读(155)  评论(0编辑  收藏  举报