anon unions are cool

From: Albert Cahalan
Date: Sun Jan 22 2006 - 19:42:42 EST


Now that the kernel requires a compiler that
supports anonymous unions, we can do some
really neat stuff.

For example, suppose we wanted to rename
a badly-named struct member. If the struct is
used all over the kernel, this becomes a giant
project with huge potential for patch conflicts.

Anonymous unions solve this. First, we replace
the badly-named struct member with an anonymous
union containing both the old name and the new
name. Second, we change much of the kernel
to use the new name. Third, we mark the old name
with the __depricated tag to generate warnings.
Fourth, we get the stragglers over days or months.
Fifth, we get rid of the anonymous union by replacing
it with the new name.

The struct evolves like so:

struct a {
int foo;
int bad;
int bar;
};

struct a {
int foo;
union {
int bad;
int baz;
};
int bar;
};

struct a {
int foo;
union {
int __deprecated bad;
int baz;
};
int bar;
};

struct a {
int foo;
int baz;
int bar;
};
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/