On Mon, 19 Mar 2007, topi wrote: > hello, > > El Mon, 19 Mar 2007 21:40:53 +0900 > "N Cocy" <novu3novrin@xxxxxxxxxxx> ha escrit: > > > Dear All, > > > > I saw the following code in linux kernel 2.6's code (arch/sparc/lib/ > > atomic32.c #L17). > > ( you can also check the code by the following url, > > http://www.linux-m32r.org/lxr/http/source/arch/sparc/lib/atomic32.c#L17) > > > > > spinlock_t __atomic_hash[ATOMIC_HASH_SIZE] = { > > > [0 ... (ATOMIC_HASH_SIZE-1)] = SPIN_LOCK_UNLOCKED > > > }; > > > > , where > > "SPIN_LOCK_UNLOCKED" returns spinlock_t type of struct, > > ATOMIC_HASH_SIZE is defined as "4" just above that function in the > > same file, > > and "spinlock_t" is defined as struct in include/linux/ > > spinlock_types.h file. > > > > Now, what does the description > > > > [0 ... (ATOMIC_HASH_SIZE-1)] = SPIN_LOCK_UNLOCKED > > > > means exactly? > > > > Does this mean initializing anonymous array or something??? like > > [0] = SPIN_LOCK_UNLOCKED > > [1] = SPIN_LOCK_UNLOCKED > > [2] = SPIN_LOCK_UNLOCKED > > [3] = SPIN_LOCK_UNLOCKED > > ??? > > yes > > > > > What I don't understand most is the part "..." in > > "[0 ... (ATOMIC_HASH_SIZE-1)]". I've never seen this description in > > C before, except for indicating possibility of additional arguments of > > a function (but it's still different from the declaration like > > "func(arg1, arg2, ...)" ). > > > this array initialization is a gnu gcc extension, documented at: > > http://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html > > "To initialize a range of elements to the same value, write `[first ... > last] = value'." the ugly part of that particular example is that it initializes an array of *unnamed* spinlocks, which is deprecated. see include/linux/spinlock_types.h for the newer interface: #define DEFINE_SPINLOCK(x) spinlock_t x = __SPIN_LOCK_UNLOCKED(x) AFAICT, all unnamed spinlocks should eventually be re-written using the new interface so that they take a "name" which can be used in debugging, but that's not going to work when you're initializing an array. in cases like that, you're probably going to have to make do with what they call a "raw" spinlock. rday -- ======================================================================== Robert P. J. Day Linux Consulting, Training and Annoying Kernel Pedantry Waterloo, Ontario, CANADA http://fsdev.net/wiki/index.php?title=Main_Page ======================================================================== -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ