Initialising const chars?

Nov 09, 2004 4 Replies

(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?


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

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.

"Fred" wrote in news:4190e2ed$0$27544$ snipped-for-privacy@news.zen.co.uk:

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

- Mark -> --

Many thanks again.

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

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required