A logging tool declares the structure below on a 64-bit Linux platform where char, short, int and double occupy 1, 2, 4 and 8 bytes and each is aligned to its own size. Fill in the byte offset of each remaining member and the total size of the structure, as whole numbers of bytes.
struct log_entry { short id; char kind; int count; char flag; double value; };
Unlock full course notes by signing up
Size of a structure with interleaved members
On a 64-bit Linux platform where char, int and double occupy 1, 4 and 8 bytes and each is aligned to its own size, what does sizeof(struct mixed) evaluate to for the declaration below? Give the answer in bytes as a whole number.
Which structure operations are permitted?
A sensor logger uses the following declarations inside a C17 function. Consider each candidate statement independently, immediately after these declarations.
The candidates are numbered only to identify their table rows.
Enter valid if a statement satisfies the C17 language constraints, or invalid otherwise. Assume no casts or compiler extensions.
A tagged union inside a structure
A parser stores values as a tagged union, declared below, on a 64-bit Linux platform where char, short, int and double occupy 1, 2, 4 and 8 bytes and each is aligned to its own size. Give each value in bytes as a whole number: the size of union value, the offset of member v within struct tagged, and the size of struct tagged.
Following a copied structure with a shared target
An inventory program copies a structure containing integer counts, an embedded array and a pointer member. Trace the following C17 code, executed inside a function.
Report the final values of stock, a.count and b.local[0]. Every requested value is a count of items; enter exact integers.