-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsizes.cpp
More file actions
52 lines (44 loc) · 1.34 KB
/
sizes.cpp
File metadata and controls
52 lines (44 loc) · 1.34 KB
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
42
43
44
45
46
47
48
49
50
51
52
//
// Print sizes of several ConsVM data structures
//
#include <stddef.h>
#include "stdio.h"
#include "stdint.h"
#include "consVM.h"
void cell_offsets()
{
Cell x;
char* base = (char *) &x;
int type_offset = (int) ((char*) &x.type - base);
int flags_offset = (int) ((char*) &x.flags - base);
printf("\n");
printf("Cell:\n");
printf(" type offset = %d\n", type_offset);
printf(" flags offset = %d\n", flags_offset);
}
void atom_offsets()
{
Atom x;
char* base = (char *) &x;
int type_offset = (int) ((char*) &x.type - base);
int flags_offset = (int) ((char*) &x.flags - base);
int next_offset = (int) ((char*) &x.next - base);
int string_offset = (int) ((char*) &x.string - base);
printf("\n");
printf("Atom:\n");
printf(" type offset = %d\n", type_offset);
printf(" flags offset = %d\n", flags_offset);
printf(" next offset = %d\n", next_offset);
printf(" string offset = %d\n", string_offset);
}
int main()
{
printf("sizeof(int) = %d\n", (int) sizeof(int));
printf("sizeof(void*) = %d\n", (int) sizeof(void*));
printf("sizeof(Cell) = %d\n", (int) sizeof(Cell));
printf("sizeof(Atom) = %d\n", (int) sizeof(Atom));
printf("sizeof(Cons) = %d\n", (int) sizeof(Cons));
printf("sizeof(String) = %d\n", (int) sizeof(String));
cell_offsets();
atom_offsets();
}