__attribute__ ((__packed__)) 紧凑方式对齐

#include <stdio.h>
#include <iostream>
 
using namespace std;
 
struct test1 {
    char c;
    int i;
};
 
struct __attribute__ ((__packed__)) test2 {
    char c;
    int i;
};
 
int main()
{
    cout << "size of test1:" << sizeof(struct test1) << endl;
    cout << "size of test2:" << sizeof(struct test2) << endl;
}

posted on 2022-09-08 09:28  lydstory  阅读(22)  评论(0)    收藏  举报

导航