I'm using MikroC for PIC, I don't know the name of the compiler. I'm using a PIC18F4550. I need to print a list of itens of a menu in a 16x4 LCD. I put here a slice of code, because the code is big to put it here, so, I tried to write here a minimal reproducible example.
The code works in the following whay: I have a stack to store the menus, the menu structure has fields as title and number of itens.
In file main.c
#include "menu.h"
int main(){
unsigned char error;
error = 0;
Tstack stackMenus;
error = menu_push(&stackMenus, &mainMenu);
}
=========================================================
In file menu.c
#include "menu.h"
const Tmenu mainMenu = {
4,
"Main Menu"
};
unsigned char menu_push( Tstack *s, PTmenu item ){
unsigned char error = 0;
if(s->topo == 9){
return 1;
}
s->pilha[++s->topo] = item;
return error;
}
======================================================
In file menu.h
struct Smenu {
unsigned char numberOfItens;
char *Title;
};
typedef struct Smenu Tmenu;
typedef Tmenu *PTmenu;
struct Sstack {
PTmenu stack[10];
signed char top;
};
typedef struct Sstack Tstack;
extern Tmenu mainMenu;
Terro menu_push(Tstack *s, PTmenu item);
I declared mainMenu as const, as pass it as argument to menu_stack. However, the compiler complains saying it is a "Illegal pointer conversion". I tryed to do
unsigned char menu_push( Tstack *s, Tmenu * const item ){ ...}
and
unsigned char menu_push( Tstack *s, const Tmenu * item ){ ...}
But the same message appears, "Illegal pointer conversion".
How can I handle that ? I need to declare the mainMenu as const because there are others menus and I'm using a microcontroller with a restricted RAM memory size.