sd-event: extend comment about a flex member

Follow-up for dbef4dd4f2. Everything that that
commit says is true, but — at least for me — it wasn't obvious why the code is
correct and we can do fixed-size allocations like new(struct inotify_data, 1).
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2025-07-03 16:35:40 +02:00
parent 391b507257
commit 9f145c2a9a
+8 -2
View File
@@ -242,6 +242,12 @@ struct inotify_data {
/* The buffer we read inotify events into */
size_t buffer_filled; /* fill level of the buffer */
union inotify_event_buffer buffer; /* struct inotify_event in union inotify_event_buffer has flex
* array. Hence, this must be at the end. */
union inotify_event_buffer buffer; /* We use a union to allow type-punning. One of the variants in
* the union — struct inotify_event — has a flex array, so C99
* only allows this union to be used at the end of the structure.
* The other variant in the union defines a fixed-size buffer that
* covers the maximum size that can be used for the flex variant,
* so in fact this field has a fixed size and could be safely
* placed in the middle of the struct. Unfortunately, there is no
* mechanism to let the compiler know that. */
};