File: cpython_ms_struct.c

package info (click to toggle)
chibicc 1.0.23.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,832 kB
  • sloc: ansic: 62,911; sh: 275; makefile: 92
file content (41 lines) | stat: -rw-r--r-- 1,058 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "test.h"
#include <stddef.h>

// Normal struct
struct Normal {
    char c;
    int i;
    short s;
};

// MS struct
struct __attribute__((ms_struct)) Ms {
    char c;
    int i;
    short s;
};

int main(void) {
    printf("sizeof(Normal) = %zu\n", sizeof(struct Normal));
    printf("  offsets: c=%zu i=%zu s=%zu\n",
           offsetof(struct Normal, c),
           offsetof(struct Normal, i),
           offsetof(struct Normal, s));

    printf("sizeof(Ms)     = %zu\n", sizeof(struct Ms));
    printf("  offsets: c=%zu i=%zu s=%zu\n",
           offsetof(struct Ms, c),
           offsetof(struct Ms, i),
           offsetof(struct Ms, s));

    ASSERT(12, sizeof(struct Normal));
    ASSERT(0,  offsetof(struct Normal, c));
    ASSERT(4,  offsetof(struct Normal, i));
    ASSERT(8,  offsetof(struct Normal, s));
    ASSERT(12, sizeof(struct Ms));
    ASSERT(0,  offsetof(struct Ms, c));
    ASSERT(4,  offsetof(struct Ms, i));
    ASSERT(8,  offsetof(struct Ms, s));
    printf("OK\n");
    return 0;
}