Hi Anton,
N.B. If you're still in Austria STOP reading and START skiing.
I've just spent a while playing about getting anonymous structs and
unions compiling under gcc 2.95. After lots of strange and unusual
ideas, I've come up with something that works well, looks OK and is
easily removeable.
There are two macros SN (Struct Name) and SC (ShortCut). These are
used to add names and hide the depth of the structures. Next each
deepest struct needs its own macro; there is no other way. I tried
macros, preprocessing, sed scripts, but to no avail. Examples...
#define SN(X) X
#define SC(P,N) P.N
struct {
union {
struct {
char *attr_name;
} SN(man);
struct {
int attr_len;
} SN(mal);
} SN(mua);
} MFT;
#define _MAN(X) SC(mua.man,X)
#define _MAL(X) SC(mua.mal,X)
I've tried to pick TLAs that are memorable. The first letter is the
from the name of the whole struct and the second and third a reminder
of the inner-most struct. The leading underscore was a vague attempt
at avoiding name clashes.
With gcc 2.96 the usage was:
MFT m;
m.attr_name = "xyz";
now it becomes:
m._MAN(attr_name) = "xyz";
The union's name is hidden away. This approach reduces the complexity
in the code (memorable macro names) and the header files aren't made
illegible either.
I've converted all the TNG code and it now compiles with gcc 2.96,
gcc 2.95 and egcs 2.91.66. Moreover the driver works :-)
At the moment the macros are in scripts/ntfsextra.h and a forcibly
included. In this state the code needs a minor bit of rearranging
to compile inline in the kernel source. The alternative is to
pre-process out the macros. I've created a couple of scripts to do
exactly this. scripts/create95 outputs gcc 2.95 compatible source
and scripts/create96 gives source suitable for gcc 2.96+.
I've checked the changes into the trunk of CVS. One excuse (too
much hassle to create a branch) and one reason (hopefully you'll be
happy with the changes :-). I tagged the code beforehand for safety's
sake "pre-95".
Cheers,
FlatCap (Rich)
nt...@fl...
|