<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi Hang Su,<div><br></div><div>Zero-length arrays at the end of a struct is a trick that you'll see in C from time to time.  Memory for the "struct pfair_param" instance is allocated dynamically with kmalloc.  When this allocation is made, more than sizeof(struct pfair_param) memory is allocated.  Thus, the subtasks array can be indexed past sizeof(struct pfair_param).</div><div><br></div><div>In sched_pfair.c, find the line "param = kmallock(…)"  Observe that extra memory is allocated with "quanta * sizeof(struct subtask)".  This allocates space for the subtask array.</div><div><br></div><div>Here's more information on this technique: <a href="http://stackoverflow.com/questions/295027/array-of-zero-length">http://stackoverflow.com/questions/295027/array-of-zero-length</a></div><div><br></div><div>-Glenn</div><div><br></div><div><br><div><div>On Feb 20, 2012, at 4:14 PM, Hang Su wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hi all:<div><br></div><div>I am reading source code about P-fair scheduling algorithm under /litmus/sched_pfair.c.<b> struct</b> subtask subtasks[0] is declared in <b>struct</b> pfair_param. From definition of function dump_subtasks(struct task_struct*t), subtasks is like a pointer to struct subtask or the name of a struct subtask array. But why it is declared as a struct subtask array with zero element ? is it as the same meaning as a pointer to struct subtask ? </div>
<div><br></div><div><br></div><div>Thanks.</div>
_______________________________________________<br>litmus-dev mailing list<br><a href="mailto:litmus-dev@lists.litmus-rt.org">litmus-dev@lists.litmus-rt.org</a><br>https://lists.litmus-rt.org/listinfo/litmus-dev<br></blockquote></div><br></div></body></html>