Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Declare

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 } };

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 } };

Name: Anonymous 2010-10-05 3:21

Thanks, but now GCC gives the error: array type has incomplete element type

Name: Anonymous 2010-10-05 3:30

Because chars can't be negative.
Try const char *foo[] = { {0x80, 0x81}, {0x90, 0x91} };

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

Name: Anonymous 2010-10-05 3:51

>>5
That's a bug in GCC. It was fixed in 4.5.2.

Name: Anonymous 2010-10-05 4:10

>>6
Uh, huh. Could you link to the patch.

Name: Anonymous 2010-10-05 4:17

>>7
Yes, it's here.
http://gcc.gnu.org/

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?

Name: Anonymous 2010-10-05 6:00

>>9
He's trying to write a C program without knowing any C, isn't it obvious?

Name: Anonymous 2010-10-05 6:20

>>4
chars can be negative.

Name: Anonymous 2010-10-05 6:30

>>11
No shit, Sherlock. >>5 isn't really a GCC bug either.

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

Name: Anonymous 2010-10-05 7:19

const charmy anus

Name: Anonymous 2010-10-05 9:24

Obviously his CFLAGS aren't set properly.

Name: Anonymous 2010-10-05 9:51

>>15
Vroom vroom!

Name: Anonymous 2011-02-03 1:36

Name: Anonymous 2011-02-04 14:51

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List