static int size_map(Map *map) { int i, sz = sizeof(map->num); /* size of nels */ MapPair *pair; for (i = 0; i < map->size; i++) { for (pair = map->table[i]; pair; pair = pair->next) { sz += size_var(pair->from); sz += size_var(pair->to); } } return sz; }
static int size_vars(Vardef *vd) { int sz = 0; for (; vd; vd = vd->next) { sz += sizeof(vd->name) + size_var(vd->value); } return sz; }
static int size_list(List *list) { int i, sz = sizeof(list->len); /* size of nels */ for (i = 0; i < list->len; i++) { sz += size_var(list->el[i]); } return sz; }
int main(void){ int a; char b; float c; long d; double e; struct A f; printf("Size of int %lu\t , sizeof() = %lu\n", size_var(a), sizeof(a)); printf("Size of char %lu\t , sizeof() = %lu\n", size_var(b), sizeof(b)); printf("Size of float %lu\t , sizeof() = %lu\n", size_var(c), sizeof(c)); printf("Size of long %lu\t , sizeof() = %lu\n", size_var(d), sizeof(d)); printf("Size of double %lu\t , sizeof() = %lu\n", size_var(e), sizeof(e)); printf("Size of Struct %lu\t , sizeof() = %lu\n", size_var(f), sizeof(f)); return 0; }