the structure is on file MNU.H
code from runmenu is on menu.c
initialization of structure is on app.h
compounds literal and c99
-
- Member
- Posts: 62
- Joined: Wed Apr 17, 2024 1:05 am
Re: compounds literal and c99
my .map file and .sym file with error programm
You do not have the required permissions to view the files attached to this post.
-
- Member
- Posts: 62
- Joined: Wed Apr 17, 2024 1:05 am
Re: compounds literal and c99
May be the problem is from static initialization of flexible array member.
Only gcc permit this.
Only gcc permit this.
Re: compounds literal and c99
Thanks so much for the source code - it fails in the same way under zxcc which eliminates a lot of variables.
Unfortunately with a vla at the end the size ends up being 32 bytes (rather than 46 for the sized variant) so only 32 bytes are copied to the stack with the result that the vla is just random stack values and garbage is printed.
Passing the value of a struct isn't performant on a z80 (and here there's really no need) so I'd always recommend passing a pointer instead.
This was the problem! All the functions take a struct as an argument rather than a struct *. So sdcc copies the structure onto the stack and passes it into the function i.e. the structure ends up becoming a local variable.The downside being that the size can't be determined, so it really only works with global structures.
Unfortunately with a vla at the end the size ends up being 32 bytes (rather than 46 for the sized variant) so only 32 bytes are copied to the stack with the result that the vla is just random stack values and garbage is printed.
Passing the value of a struct isn't performant on a z80 (and here there's really no need) so I'd always recommend passing a pointer instead.
-
- Member
- Posts: 62
- Joined: Wed Apr 17, 2024 1:05 am
Re: compounds literal and c99
Thanks for investing time on my problem, I will test this.
-
- Member
- Posts: 62
- Joined: Wed Apr 17, 2024 1:05 am
Re: compounds literal and c99
it work now passing pointer to function,
Thank you very much.
Thank you very much.
-
- Member
- Posts: 62
- Joined: Wed Apr 17, 2024 1:05 am
Re: compounds literal and c99
now that it works by passing a pointer to the functions, the following initialization, in addition to declaring the menu item like this in the menu structure
const char **item_menu;
All work great.
const char **item_menu;
Code: Select all
typedef struct
{
int x;
int y;
int nb_item;
int width_item_max;
int item_default;
int item_selected;
int bg;
int fg;
int bg_sel;
int fg_sel;
const char **item_menu;
} MNU;
static const char *main_menu_items[] = {
"System Color ",
"Test input ",
"Ascii chart ",
"Horizontal menu ",
"Submenu test demo > ",
"Test box frame ",
"Quit application ",
NULL
};
static MNU main_menu = {5, 5, 7, 20, 1, -1, Black, White, Cyan, Black, {main_menu_items} };