0

In a bit of code I'm looking at, a 3D array has been initialized like so:

static const char codeset[6][256][10] = {
 [0] = { [0x20] = " ",
 [0x21] = "!",
 [0x22] = """,
 [0x23] = "#",
}};

(It does go on to initialize the rest of the cells, I've cut it short to show something readable.)

This does not compile. Is it supposed to? What's going on here?

unwind
402k64 gold badges491 silver badges619 bronze badges
asked Nov 29, 2010 at 10:37
4
  • Could we have the error message ? Commented Nov 29, 2010 at 10:44
  • syntax error : '[', pointing to the line with [0]. Commented Nov 29, 2010 at 10:48
  • 1
    Compiles for me correctly (gcc 4.5.1). If you're on GCC, you can add -std=c99 to your command line just to be on the safe side, as it's a C99 extension. Commented Nov 29, 2010 at 11:51
  • Alas, I'm in Visual studio, and apparently it's not going to work there: eggheadcafe.com/software/aspnet/34012666/… Commented Nov 29, 2010 at 12:05

3 Answers 3

3

You are using C99 initializers, but your compiler does not support C99 or C99 is not enabled.

answered Nov 29, 2010 at 11:51
Sign up to request clarification or add additional context in comments.

Comments

2

You are trying to use C99 initializers, but most likely your compiler isn't C99-compliant, otherwise it would work.

answered Nov 29, 2010 at 11:44

2 Comments

Good link, but unless my reading skills are bugged, it states that it's C99 extension, not GCC extension. GCC extends upon this by allowing to initialize ranges. +1 anyway as the link explains what's going on here. I didn't know that one too :)
@Kos Thanks, corrected. I was so much sure it is GCC-only so I didn't read thoughtfully.
0

As a guess, it trying to create the "alphabet" for xml string ASCII data. The " (double quote) character in xml is represented as &quot. So the [0][0 - 255] group is xml.

It looks like an equivalence table. It translates from xml to ASCII or whatever.

answered Nov 29, 2010 at 10:47

1 Comment

Heh, maybe I was unclear - I know what the point of the array is, I want to know what's the problem with the initialization (Which, from what I've read, isn't actually supposed to work like that).

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.