Declare
1
Name:
Anonymous
2010-10-05 2:46
Why is the above legal, but the bottom is not? I'm using GCC 4.5.1.
const char *Array[] = { "asdfas", "sdfasd" };
const char *Array[] = { { -8, 1, 23, 42, -42, 12 }, { 14, 23, 123, -85, 34 } };
2
Name:
Anonymous
2010-10-05 3:15
Because the bottom should be
const char *Array[][] = { { -8, 1, 23, 42, -42, 12 }, { 14, 23, 123, -85, 34 } };
3
Name:
Anonymous
2010-10-05 3:21
Thanks, but now GCC gives the error: array type has incomplete element type
4
Name:
Anonymous
2010-10-05 3:30
Because chars can't be negative.
Try const char *foo[] = { {0x80, 0x81}, {0x90, 0x91} };
5
Name:
Anonymous
2010-10-05 3:36
>>4
Still doesn't compile.
test.c:5:2: warning: braces around scalar initializer
test.c:5:2: warning: (near initialization for 'foo[0]')
test.c:5:2: warning: initialization makes pointer from integer without a cast
6
Name:
Anonymous
2010-10-05 3:51
>>5
That's a bug in GCC. It was fixed in 4.5.2.
7
Name:
Anonymous
2010-10-05 4:10
>>6
Uh, huh. Could you link to the patch.
8
Name:
Anonymous
2010-10-05 4:17
9
Name:
Anonymous
2010-10-05 4:26
Because you're trying to assign to a const char * with an initializer list. What exactly are you trying to do?
10
Name:
Anonymous
2010-10-05 6:00
>>9
He's trying to write a C program without knowing any C, isn't it obvious?
11
Name:
Anonymous
2010-10-05 6:20
>>4
chars
can be negative.
12
Name:
Anonymous
2010-10-05 6:30
>>11
No shit, Sherlock.
>>5 isn't really a GCC bug either.
13
Name:
Anonymous
2010-10-05 7:16
const char *Array[] = {(const char []){-8,1,23,42,-42,12}, (const char []){14,23,123,-85,34}};
C99
14
Name:
Anonymous
2010-10-05 7:19
const charmy anus
15
Name:
Anonymous
2010-10-05 9:24
Obviously his CFLAGS aren't set properly.
16
Name:
Anonymous
2010-10-05 9:51
17
Name:
Anonymous
2011-02-03 1:36