1

I am making a multi-language interface for an AVR system, the strings are stored in the program memory with each language string placed in its own array. The idea is that when the user switches language, the pointer that contains the address of the currently selected language array will change. I have difficulties understanding the correct type of pointer I should use to point to these arrays. With the current code, I am getting a warning of "assignment discards 'const' qualifier from pointer target type".

Here is the code:

Languages.c:

const MEMORY_PREFIX wchar_t* const  Greek_text[] =
{
    [INITIAL_FEED_TEXT] = (const MEMORY_PREFIX wchar_t[]) {L"γεμισμα"},
    [NORMAL_BURN_TEXT] = (const MEMORY_PREFIX wchar_t[]) {L"Πληρης Καυση"},
}

const MEMORY_PREFIX wchar_t* const  English_text[] =
{
    [INITIAL_FEED_TEXT] = (const MEMORY_PREFIX wchar_t[]) {L"Initial Feed"},
    [NORMAL_BURN_TEXT] = (const MEMORY_PREFIX wchar_t[]) {L"Normal Burn"},
}

Languages.h:

#define MEMORY_PREFIX __flash
extern  const MEMORY_PREFIX wchar_t* const  Greek_text[];
extern  const MEMORY_PREFIX wchar_t* const  English_text[];

typedef enum lang_pt
{
    INITIAL_FEED_TEXT,
    NORMAL_BURN_TEXT
}lang_pt_t;

Menu.h:

typedef enum Language
{
 English,
 Greek,
}Language_type_t;

void Menu_select_language(void);

Menu.c:

static const MEMORY_PREFIX wchar_t** Unicode_text = Greek_text;

void Menu_select_language(Language_type_t language)
{
    /*Assign a language table to the language table pointer*/
    switch (language)
    {
    case English:
        Unicode_text = English_text;
        break;
    case Greek:
        Unicode_text =Greek_text;
        break;
    default:
        Unicode_text = English_text;
        break;
    }
}
1
  • 1
    If only unordered_map where constexpr then you could use Unicode_text["Initial Feed"] for lookups without needing the enum. Commented Jul 18, 2022 at 11:39

2 Answers 2

4

The number of the qualifier const in the declaration of a pointer

static const MEMORY_PREFIX wchar_t** Unicode_text = Greek_text;

does not corresponds to the number of the qualifier in the arrays.

You should write

static const MEMORY_PREFIX wchar_t * const * Unicode_text = Greek_text;
Sign up to request clarification or add additional context in comments.

Comments

3

You should add additional const qualifier:

static const MEMORY_PREFIX wchar_t* const * Unicode_text = Greek_text;

because not only the strings are constants, but the arrays of strings are constants too.

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.