[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Type macros and friends
From: |
Johan Rydberg |
Subject: |
Type macros and friends |
Date: |
Tue, 15 Feb 2005 00:15:45 +0100 |
User-agent: |
Gnus/5.1007 (Gnus v5.10.7) Emacs/21.3 (gnu/linux) |
Hi,
I was browsing through the libl4 headers earlier today, and got to
thinking about constructs like the following:
typedef _L4_RAW (_L4_api_version_t, _L4_STRUCT1 ({
_L4_BITFIELD4
(_L4_word_t,
_L4_BITFIELD (__pad1, 16),
/* The subversion or revision. */
_L4_BITFIELD (subversion, 8),
/* The interface version. */
_L4_BITFIELD (version, 8),
_L4_BITFIELD_64 (__pad2, 32));
})) __L4_api_version_t;
Which results more or less in a union that looks like:
union foo
{
int raw;
struct {
int x : 16;
int y : 16;
};
};
This make "x" and "y" visible in the "foo" scope. For example:
union foo foo = { .raw = X };
printf ("%x\n", foo.x);
All good, but what if you want to declare a "foo" staticly? Like this:
union foo bar =
{
.x = 10, .y = 20
};
In this case "x" and "y" are _NOT_ available in the "foo" scope. This
is extremely limiting, from my point of view. I've tried a gazillion
combinations to try to make a static construct, but have yet to succeed.
bar.c:13: unknown field `x' specified in initializer
Anyone got any ideas how a static construct can be created in this
case?
~j
- Type macros and friends,
Johan Rydberg <=