Re: Using C99 in the kernel was Re: [PATCH 1/19] MUTEX: Introduce simple mutex implementation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux