N
Noob
Hello everyone,
I was playing around with arrays, when I noticed something
I don't understand.
Consider the following code:
extern int u[10];
int v[10];
int x[10] = { };
int y[10] = { 0 };
int z[10] = { 42 };
y and z are proper array definitions, while u is merely
a declaration. But what about v and x?
On my platform, objdump says:
00000000 g O .data 00000028 _z
00000000 g O .bss 00000028 _y
00000028 g O .bss 00000028 _x
00000028 O *COM* 00000004 _v
No mention of u, which is expected for a declaration.
y in bss, expected since it's all-0.
z in data, expected because it's not all-0.
Apparently, x is equivalent to y.
So int x[10] = { }; is a proper definition?
(Can you cite C&V allowing this syntax?)
I'm puzzled with v. It seems to have been considered
a pointer? (Since the size is 4.) Did my compiler
consider this a tentative definition?
I would have expected v to be equivalent to x and y.
I suppose I was wrong, given the output?
So I have to use x or y syntax to define an empty array?
Relevant links
http://stackoverflow.com/questions/2331584/global-variable-implementation
http://david.tribble.com/text/cdiffs.htm#C99-odr
Regards.
I was playing around with arrays, when I noticed something
I don't understand.
Consider the following code:
extern int u[10];
int v[10];
int x[10] = { };
int y[10] = { 0 };
int z[10] = { 42 };
y and z are proper array definitions, while u is merely
a declaration. But what about v and x?
On my platform, objdump says:
00000000 g O .data 00000028 _z
00000000 g O .bss 00000028 _y
00000028 g O .bss 00000028 _x
00000028 O *COM* 00000004 _v
No mention of u, which is expected for a declaration.
y in bss, expected since it's all-0.
z in data, expected because it's not all-0.
Apparently, x is equivalent to y.
So int x[10] = { }; is a proper definition?
(Can you cite C&V allowing this syntax?)
I'm puzzled with v. It seems to have been considered
a pointer? (Since the size is 4.) Did my compiler
consider this a tentative definition?
I would have expected v to be equivalent to x and y.
I suppose I was wrong, given the output?
So I have to use x or y syntax to define an empty array?
Relevant links
http://stackoverflow.com/questions/2331584/global-variable-implementation
http://david.tribble.com/text/cdiffs.htm#C99-odr
Regards.