Const expression expected

Post your reviews about the boards you have got.
Post Reply
Author
Message
Luyar
Posts: 1
Joined: 16 Mar 2022 16:09

Const expression expected

#1 Post by Luyar » 16 Mar 2022 21:24

Hi

What am i doing wrong here :

void RGBLCD1602_command(unsigned int value)
{
unsigned int lcddata[3] = {0x80 , value};
RGBLCD1602_send( LCD_ADDRESS , lcddata , 2);
}

I get a compiler error :

Const expression expected
Too many initializers

Thanks,

User avatar
darko.ilijevski
Posts: 581
Joined: 21 Mar 2017 16:57

Re: Const expression expected

#2 Post by darko.ilijevski » 21 Mar 2022 18:35

Hello,

The problem is the following line:

Code: Select all

unsigned int lcddata[3] = {0x80 , value};
You can't initialize an array with variables. Only constants and literals. For example, this would work:

Code: Select all

const int value = 0xA0;
unsigned int lcddata[3] = {0x80 , value};
BR,
Darko

Post Reply

Return to “Review”