0

I want to initialize a array. But ı have two different initial values in compile time. So I want to do it in precompile time. My code is

static const U8 userFont[8][8] =
{   
#if (LCD_LANGUAGE == LANG_1)
    { 0x0E, 0x09, 0x09, 0x1D, 0x09, 0x09, 0x0E, 0x00 }, 
    { 0x03, 0x0E, 0x11, 0x10, 0x10, 0x11, 0x0E, 0x00 }, 
    { 0x09, 0x06, 0x0F, 0x01, 0x02, 0x04, 0x0F, 0x00 }, 
    { 0x0E, 0x11, 0x10, 0x10, 0x15, 0x0E, 0x04, 0x00 }, 
    { 0x11, 0x0E, 0x11, 0x10, 0x10, 0x11, 0x0E, 0x00 }, 
    { 0x19, 0x06, 0x09, 0x04, 0x02, 0x09, 0x06, 0x00 }, 
    { 0x00, 0x01, 0x01, 0x01, 0x01, 0x03, 0x03, 0x03 },     
    { 0x03, 0x03, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01 }      
#elif (LCD_LANGUAGE == LANG_2)
    { 0x0A, 0x00, 0x11, 0x11, 0x11, 0x11, 0x0E, 0x00 },     
    { 0x04, 0x00, 0x1E, 0x04, 0x04, 0x04, 0x1E, 0x00 },     
    { 0x0A, 0x00, 0x0E, 0x11, 0x11, 0x11, 0x0E, 0x00 },     
    { 0x0E, 0x11, 0x10, 0x10, 0x11, 0x0E, 0x04, 0x00 },     
    { 0x0F, 0x10, 0x10, 0x0E, 0x01, 0x1E, 0x04, 0x00 },     
    { 0x0E, 0x00, 0x0F, 0x10, 0x17, 0x11, 0x0F, 0x00 },     
    { 0x01, 0x01, 0x01, 0x01, 0x01, 0x03, 0x03, 0x03 },     
    { 0x03, 0x03, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01 }  

#endif
};

But I get this error : "expected an expression". Error given at the end of array. So how can I solve this problem?

2 Answers 2

2

A couple of questions:

  1. Have you defined the type U8 with something like typedef unsigned char U8;?
  2. Have you defined LCD_LANGUAGE as either LANG_1 or LANG_2?

The reason I ask is because this little snippet below compiles and runs just fine:

#include <stdio.h>
typedef unsigned char U8;
#define LCD_LANGUAGE LANG_1
static const U8 userFont[8][8] =
{
#if (LCD_LANGUAGE == LANG_1)
    { 0x0E, 0x09, 0x09, 0x1D, 0x09, 0x09, 0x0E, 0x00 },
    { 0x03, 0x0E, 0x11, 0x10, 0x10, 0x11, 0x0E, 0x00 },
    { 0x09, 0x06, 0x0F, 0x01, 0x02, 0x04, 0x0F, 0x00 },
    { 0x0E, 0x11, 0x10, 0x10, 0x15, 0x0E, 0x04, 0x00 },
    { 0x11, 0x0E, 0x11, 0x10, 0x10, 0x11, 0x0E, 0x00 },
    { 0x19, 0x06, 0x09, 0x04, 0x02, 0x09, 0x06, 0x00 },
    { 0x00, 0x01, 0x01, 0x01, 0x01, 0x03, 0x03, 0x03 },
    { 0x03, 0x03, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01 }
#elif (LCD_LANGUAGE == LANG_2)
    { 0x0A, 0x00, 0x11, 0x11, 0x11, 0x11, 0x0E, 0x00 },
    { 0x04, 0x00, 0x1E, 0x04, 0x04, 0x04, 0x1E, 0x00 },
    { 0x0A, 0x00, 0x0E, 0x11, 0x11, 0x11, 0x0E, 0x00 },
    { 0x0E, 0x11, 0x10, 0x10, 0x11, 0x0E, 0x04, 0x00 },
    { 0x0F, 0x10, 0x10, 0x0E, 0x01, 0x1E, 0x04, 0x00 },
    { 0x0E, 0x00, 0x0F, 0x10, 0x17, 0x11, 0x0F, 0x00 },
    { 0x01, 0x01, 0x01, 0x01, 0x01, 0x03, 0x03, 0x03 },
    { 0x03, 0x03, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01 }
#endif
};
int main (void) {
    printf ("0x%02x 0x%02x\n", userFont[0][0], userFont[2][2]);
    return 0;
}

producing:

0x0e 0x0f
Sign up to request clarification or add additional context in comments.

Comments

1

LANG_1 AND LANG_2 is enum so in procompile time this objects are invalid. So I replace wtih integral values my problem is solved. Thanks.

Comments

Your Answer

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.