I'm going through the kernel linux source code reading just to improve my knowledge of it.
I just stepped into the declaration of a structure where there's some strange "just one element arrays".
I'm trying to figuring out why use one element array and not the istance of the type.
Here the code I'm referring to
struct files_struct {
/*
* read mostly part
*/
atomic_t count;
bool resize_in_progress;
wait_queue_head_t resize_wait;
struct fdtable __rcu *fdt;
struct fdtable fdtab;
/*
* written part on a separate cache line in SMP
*/
spinlock_t file_lock ____cacheline_aligned_in_smp;
unsigned int next_fd;
unsigned long close_on_exec_init[1];
unsigned long open_fds_init[1];
unsigned long full_fds_bits_init[1];
struct file __rcu * fd_array[NR_OPEN_DEFAULT];
};
For example why in place of unsigned long close_on_exec_init[1]; they do not just declared unsigned long close_on_exec_init;.