Bzzt. Arrays and pointers are not always equivalent. This code
defines an area of 4*IFNAMSIZ chars. The old code then initialised
each IFNAMSIZ chars to the empty string (an array starting with '\0'),
not a pointer to an empty string. Test file x.c.
#define IFNAMSIZ 7
static char name[4][IFNAMSIZ];
int main(void) { return(0); }
# gcc -g x.c -o x
# gdb x
(gdb) ptype name
type = char [4][7]
(gdb) x name[0]
0x80494f4 <name>: 0x00000000
(gdb) x name[1]
0x80494fb <name+7>: 0x00000000
(gdb) x name[2]
0x8049502 <name+14>: 0x00000000
(gdb) x name[3]
0x8049509 <name+21>: 0x00000000
Zero initialisation via bss works fine. Try it with
static char name[4][IFNAMSIZ] = {"", "", "", ""};
and you get exactly the same results, at the expense of more disk space
and time to load. Not much extra I know, but it all adds up.
-
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/