D
D
DEUS2020-05-22 10:48:30
C++ / C#
DEUS, 2020-05-22 10:48:30

How is structure packing going on here?

I enter 1 record from the keyboard, I pack it as a structure into a binary file. I don't understand how alignment works in this case.
The first 2 fields of the record are strings (static), the maximum length (set by me) of the first field is 30 characters + 1 under '\0', the second has 15 similarly. 3 and 4 int fields. I pack the structure, it packs the first field into 31 bytes, and then the second field immediately begins. The first is clearly not aligned, it turns out that if, for example, as I understand it, 3 and 4 fields are aligned by 4, then the first should have aligned to 32.
How is the structure packed here?
I enter the following entry: name producer 1 2
5ec783b6861f5613254611.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2020-05-22
@Qpz111

How is the structure packed here?

The picture clearly shows the first field (31 bytes), the second field (16 bytes), a hole of 1 byte, the third field (4 bytes), the fourth field (4 bytes).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question