【发布时间】:2014-07-24 14:21:05
【问题描述】:
请注意:此问题与(One element array in struct)不重复
以下代码摘自Linux内核源码(版本:3.14)
struct files_struct
{
atomic_t count;
struct fdtable __rcu *fdt;
struct fdtable fdtab;
spinlock_t file_lock ____cacheline_aligned_in_smp;
int next_fd;
unsigned long close_on_exec_init[1];
unsigned long open_fds_init[1];
struct file __rcu * fd_array[NR_OPEN_DEFAULT];
};
我只是想知道为什么close_on_exec_init 和open_fds_init 被定义为包含一个元素的数组,而不仅仅是定义为unsigned long close_on_exec_init; 和unsigned long open_fds_init;。
【问题讨论】:
-
也很好解释here
-
看起来它不可能是灵活数组的破解,因为数组成员不在末尾。
-
上面给出的帖子与这个问题不同。而且答案不适用于这个问题。
-
@xmllmx 你能解释一下你的问题有什么不同吗?
-
@Code-Guru,数组字段数多于一个,而不是最后一个字段。
标签: c arrays linux struct idioms