On Mon, 5 Aug 2002, Patrick Mochel wrote:
> [1]: The reason for the macro is because the driverfs internals
> have changed enough to be able to support attributes of any type. In
> order to do this in a type-safe manner, we have a generic object type
> (struct attribute) that we use. We pass this to an intermediate layer
> that does a container_of() on that object to obtain the specific
> attribute type.
Of course that means that it's not really type-safe, since it has no way
to check whether the object is embedded in the right type of struct, right
;) (But I think that's okay, C doesn't have provisions for real
inheritance)
> This means the specific attribute types have an embedded struct
> attribute in them, making the initializers kinda ugly. I played with
> anonymous structs and unions to have something that could
> theoretically work, but they apparently don't like named
> initializers.
Have you considered just putting in the embedded part via some macro -
I think that's what NTFS does for compilers which don't support unnamed
structs.
Basically
#define EMB_ATTRIBUTE \
int emb1;
int emb2
struct my_attribute {
EMB_ATTRIBUTE
int my1;
int my2;
};
That'll work with named initializers just fine, so the users don't have to
deal with ugly DEVICE_ATTR macros, where one forgets if parameter #3 was
show or store ;) - It follows the common way of hiding away unavoidable
ugliness in some header.
> [2]: I wanted to consolidate the first two parameters, but I couldn't
> find a way to stringify ##name (or un-stringify "strname"). Is that
> even possible?
Why would stringify (include/linux/stringify.h) not work? However, Al Viro
may get mad at you for generating ungreppable symbols either way ;-)
--Kai
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
This archive was generated by hypermail 2b29 : Wed Aug 07 2002 - 22:00:28 EST