Re: [PATCH] 2.5 fast poll on ppc64

Linus Torvalds
2002-12-26T21:21:29Z

On Thu, 26 Dec 2002, Mikael Pettersson wrote:
>
> Technically speaking, the kernel code which uses 'entries[0]' is
> non-compliant since the proper syntax is 'entries[]', but the empty
> array size syntax isn't implemented in gcc 2.95.3.

The two things have two totally different semantics:

- array[0] is a zero-sized array, and is a long-time gcc extension that
has nothing to do with the modern "flexible array". The kernel uses
zero-sized arrays, because flexible arrays simply aren't historically
supported by gcc at all.

- array[] is the standard "flexible array" thing, and has different rules
than array[0]. For example, sizeof() is undefined on flexible arrays,
but is well-defined on zero-sized ones (at zero). Also, the alignment
constraints are potentially quite different.

The gcc people want to make the two behave fairly similarly to ease
implementation issues, but they are definitely not the same.

> My mistake. The old code is Ok for C99, but broken for ANSI-C.

The old code is ugly and arguably always broken, I agree 100% with making
the usage code use "pp->entries". Whether the allocators use "sizeof" or
"offsetof" is secondary, at worst it ends up being conservative.

Linus