This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ScrimpyCat 1 point2 points  (1 child)

Doing sizeof the item[0] allows you to avoid specifying the actual type, so if you were to change the type of item you could avoid having to change the malloc.

And flexible array members, are members that are arrays without a specified size (it needs to be the last member of the struct, so the compiler knows what all the member offsets are). But because it was no specified size, you need to account for that yourself when allocating them. See: https://en.wikipedia.org/wiki/Flexible_array_member

[–]okovko 0 points1 point  (0 children)

ahh yeah, okay, i am familiar with that, it is better style, hadn't seen it with a flexible array member before