View previous topic :: View next topic |
Author |
Message |
NWilson
Joined: 30 Jun 2011 Posts: 21 Location: King's Lynn. England
|
Help Please! Expression must evaluate to a constant (Solved) |
Posted: Thu Nov 16, 2023 8:37 am |
|
|
PCWHD Version 5.116
Hi all,
I’m trying to produce a hardware clone of an old instrument based on a siemens SAB-C165 microprocessor and port the code over to a PIC24FJ128GC006.
The instrument has dozens of menus with lots of messages and associated actions. TBH, being a hardware engineer, I am struggling to get the menu system ported over.
Can anyone help me out with the following error?
*** Error 27 "C:\Development\Hardware Clone\main.c" Line 69(4,5): Expression must evaluate to a constant
Here is a simplified snippet of code that shows the problem.
Code: | //****************************************************
// main.c
// Rev : 1.0
// Start Date : 16th November 2023
// Author : Neil Wilson
//*********************************************************
#EXPORT (FILE=Menu_Test.hex)
#include <24FJ128GC006.h>
#device ANSI
#device ADC=12
#device ICD=TRUE
#device ICSP=1
#use delay(internal=32000000)
#FUSES NOWDT //No Watch Dog Timer
#FUSES CKSFSM //Clock Switching is enabled, fail Safe clock monitor is enabled
#define MENU_INTRO 0
#define MENU_MAIN 1
#define MENU_FILE 2
#define MENU_SYS 3 //Lots of menus ........
#define BLANK 0
#define MESS_ACC1 1
#define MESS_ADC1 2
#define MESS_ADC2 3
#define MESS_CLE1 4
#define MESS_CHE2 5
#define MESS_BATLOW 6 // Lots of messages......
// a snippet of dictionary entries - lots of them!
const char *message [] =
{
" ", // 0 BLANK
"Acceptable Range", // 1 MESS_ACC1
"ADC Setup", // 2 MESS_ADC1
"ADC Test", // 3 MESS_ADC2
"Clearing Memory ....", // 4 MESS_CLE1
"Check PSU", // 5 MESS_CHE2
"** Battery Low ! ** " // 6 MESS_BATLOW
};
struct zMenu
{
int cText[8]; // dictionary index for each display line
unsigned char cAction[8]; // action code for each display line
unsigned char cCsr; // initial line for cursor to start from
unsigned char cEscape; // action on escape key
unsigned char cTitle; // title inverted flag
void (*func)(void); // function associated with this menu
};
const struct zMenu sMenu0 = // Menu 0 MENU_INTRO
{
MESS_CLE1,
MESS_CHE2,
MESS_BATLOW
};
const struct zMenu sMenu1 = // Menu 1 = MENU_MAIN
{
MESS_ACC1,
MESS_ADC1,
MESS_ADC2
};
const struct zMenu *g_sMenu [] =
{
{&sMenu0}, {&sMenu1}
};
void showMenu (unsigned char cPage)
{
unsigned char cLine;
int8 cIndex;
char chText[5], chBuff[25];
cLine = 0; // reset line pointer
cIndex = g_sMenu[cPage]->cText[cLine]; // find dictionary entry
strcpy(chBuff, message[cIndex]); // format string on display line
//display_string_xy(1, cLine, chBuff); // display string on LCD
return;
}
void main()
{
showMenu(MENU_MAIN);
while(1)
{;}
}
|
It's this bit, that it doesn't seem to like.
Code: | const struct zMenu *g_sMenu [] =
{
{&sMenu0}, {&sMenu1}
}; |
Thanks in advance
Neil
Last edited by NWilson on Fri Nov 17, 2023 2:41 am; edited 2 times in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Thu Nov 16, 2023 12:42 pm |
|
|
Start by getting rid of the const declarations.
You should find that things then work.
Then do a search here for why const is different in CCS from the ANSI
usage. It is fundamental and matters massively. There are ways partially
round this, but a lot of thought is needed, and the simplest will be to not
use const. |
|
|
NWilson
Joined: 30 Jun 2011 Posts: 21 Location: King's Lynn. England
|
|
Posted: Thu Nov 16, 2023 1:26 pm |
|
|
Thanks Ttelmah,
I'll try that tomorrow when I get to work. |
|
|
NWilson
Joined: 30 Jun 2011 Posts: 21 Location: King's Lynn. England
|
|
Posted: Thu Nov 16, 2023 1:34 pm |
|
|
I've just removed all the const declarations from the above code and it still gives me the same error.
I'm open to suggestions if anyone can help.
Best wishes
Neil |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Fri Nov 17, 2023 2:32 am |
|
|
OK. The const part was going to give you problems later.
struct zMenu *g_sMenu [2] = {&sMenu0,&sMenu1}; |
|
|
NWilson
Joined: 30 Jun 2011 Posts: 21 Location: King's Lynn. England
|
|
Posted: Fri Nov 17, 2023 2:39 am |
|
|
Brilliant! Thanks Ttelmah |
|
|
|