On the initialization of structures
[Posted July 24, 2002 by corbet]
The kernel source contains a great many structures which are initialized at
compile time. Back in the 2.3 development series, substantial effort went
into converting all of those initializations into the gcc designated
initialization format:
struct something my_struct = {
field_1: value,
field_2: value,
...
};
The advantage of this format, of course, is that it is possible to clearly
initialize a subset of the structure's fields and not have things break if
the declaration of the structure changes. It was a good change which
cleaned up a lot of code.
There's only one problem: the C99 standard chose a different format.
Standard-compliant C should instead contain initializations that look like:
struct something my_struct = {
.field_1 = value,
.field_2 = value,
...
};
After a bit of discussion, the kernel hackers have decided to, you guessed
it, convert all of the structure initializations in the kernel to the new
format. Those changes are starting to find their way into the mainline; all new code
should certainly be done the standard way.
(
Log in to post comments)