Re: [PATCH] net #9

From: Keith Owens (kaos@ocs.com.au)
Date: Wed May 30 2001 - 05:30:18 EST


On Wed, 30 May 2001 09:32:39 +0000 (UTC),
"Henning P. Schmiedehausen" <mailgate@hometree.net> wrote:
>Andrzej Krzysztofowicz <ankry@green.mif.pg.gda.pl> writes:
>
>>-static char name[4][IFNAMSIZ] = { "", "", "", "" };
>
>>+static char name[4][IFNAMSIZ];
>
>Ugh. Sure about that one? the variables have been pointers to zero,
>now they're zero...

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/



This archive was generated by hypermail 2b29 : Thu May 31 2001 - 21:00:45 EST