【发布时间】:2015-12-02 04:41:55
【问题描述】:
我正在研究 Linux 内核(特别是负载平衡区域)。 在内核(sched.h)中有一个结构声明:
结构 sched_group
看起来像这样:
struct sched_group {
struct sched_group *next; /* Must be a circular list */
atomic_t ref;
unsigned int group_weight;
struct sched_group_power *sgp;
/*
* The CPUs this group covers.
*
* NOTE: this field is variable length. (Allocated dynamically
* by attaching extra space to the end of the structure,
* depending on how many CPUs the kernel has booted up with)
*/
unsigned long cpumask[0];
};
我不明白的是使用大小为 0 的 cpumask 数组。 任何解释将不胜感激:)
【问题讨论】:
-
这是通常称为the struct hack 的GCC 变体。 C 标准不包括这种行为。
标签: c linux linux-kernel