lkml.org 
[lkml]   [2005]   [Dec]   [13]   [last100]   RSS Feed
Views: [more markup]  [less markup]  [headers]  [forward] 
 
Messages in this thread
/
DateTue, 13 Dec 2005 23:05:36 +0000
FromAl Viro <>
SubjectRe: Using C99 in the kernel was Re: [PATCH 1/19] MUTEX: Introduce simple mutex implementation
On Tue, Dec 13, 2005 at 10:56:10PM +0100, Andi Kleen wrote:
> It looks like casts in constant initializers for global structures are not 
> allowed anymore: struct foo x = (struct foo) { ... }; warns.  That's
> not good because when the (struct foo){} is generated in a macro
> then it's the only easy way to allow initialization outside a declaration.
> 
> Common case is SPIN_LOCK_UNLOCKED() / DEFINE_SPINLOCK().

There are two similar things - struct initializers and compound literals.
They are *not* the same, though; compound literal defines an unnamed
object, so
{
	struct foo x = (struct foo){...};
is equivalent to
	struct foo unnamed_variable = {....};
	struct foo x = unnamed_variable;
For auto variables it's fine; there initializer doesn't have to be
constant.  For globals it's _not_.

Note that it's really a definition of object - e.. you can say
	f(&(struct foo){....});
and have it work just fine.
IOW, DEFINE_SPINLOCK() should be spinlock_t x = __SPIN_LOCK_UNLOCKED()
and SPIN_LOCK_UNLOCKED - (spinlock_t) __SPIN_LOCK_UNLOCKED.  That's
enough to make it valid C99...
-
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/

\
 
 \ /
  Last update: 2005-12-14 00:08    [from the cache]
©2003-2008