diff options
-rw-r--r-- | rt_struct.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/rt_struct.c b/rt_struct.c index b4840ac..c309883 100644 --- a/rt_struct.c +++ b/rt_struct.c @@ -50,8 +50,6 @@ int create_rts(rts_type *type) { } else { size_t offset = 0; size_t max_align = 0; - size_t remainder = 0; - size_t padding = 0; const int num_members = member_count(type); rts_member **members = type->members; @@ -68,18 +66,23 @@ int create_rts(rts_type *type) { const size_t align = member_type->alignment; max_align = max(max_align, align); if (type->tag == TAG_STRUCT) { - remainder = offset % align; - padding = (remainder) ? align - remainder : 0; - offset += padding; + if (!type->is_packed) { + const size_t remainder = offset % align; + const size_t padding = (remainder) ? align - remainder : 0; + offset += padding; + } type->offsets[i] = offset; offset += member_size(members[i]); } } } - type->alignment = max_align; - remainder = offset % max_align; - padding = (remainder) ? max_align - remainder : 0; - type->size = offset + padding; + if (!type->is_packed) { + const size_t remainder = offset % max_align; + const size_t padding = (remainder) ? max_align - remainder : 0; + offset += padding; + } + type->alignment = (!type->is_packed) ? max_align : 0; + type->size = offset; return 0; } } |