Initialising const chars?

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
(This is best viewed with a fixed width font)

With one compiler I would use something like:

const char 2darrayofchars[][4] = {
            0x00, 0x01, 0x02, 0x03,
            0x00, 0x01, 0xff, 0x02,
            0x00, 0x01, 0x02, 0xff,
            0x00, 0x01, 0xff, 0xff,
            0x00, 0xff, 0x01, 0x02,
            0x00, 0x01, 0x02, 0xff,
            0x00, 0xff, 0x01, 0xff
           };

However the SDCC compiler doesn't like this and makes remarks about curly
brackets.

The only example I have found is:

char arr2[5][20] = {  "Mickey Mouse",
                      "Donald Duck",
                      "Minnie Mouse",
                      "Goofy",
                      "Ted Jensen" };

but naturally this uses strings which is not helpful.

Can anyone point me in the right direction?  Is there a best newsgroup for
this sort of question?



Re: Initialising const chars?
Quoted text here. Click to load it

How about this:

const char a2darrayofchars[][4] = {
           {0x00, 0x01, 0x02, 0x03},
           {0x00, 0x01, 0xff, 0x02},
           {0x00, 0x01, 0x02, 0xff},
           {0x00, 0x01, 0xff, 0xff},
           {0x00, 0xff, 0x01, 0x02},
           {0x00, 0x01, 0x02, 0xff},
           {0x00, 0xff, 0x01, 0xff}
          };

Re: Initialising const chars?

Quoted text here. Click to load it
curly

Many thanks - I thought for a minute I was going mad because I believed I
had already tried this.  I had indeed and it didn't work.

I get this error

"myprog.c":"line_number": error: struct/union/array '2darrayofchars'
:initialisation needs curly braces

I get 3 of these errors per line of constants 28 + one at the last curly
brace.



Re: Initialising const chars?

Quoted text here. Click to load it


Yes, it is good to remember that identifiers may not start with a number.

--
- Mark ->
--

Re: Initialising const chars?

Quoted text here. Click to load it

Many thanks again.

Your principle was correct - I had tried this before and can only think on
this occasion I altered the "wrong" file.



Site Timeline