compounds literal and c99

andromeda92
Member
Posts: 62
Joined: Wed Apr 17, 2024 1:05 am

Re: compounds literal and c99

Post by andromeda92 »

the structure is on file MNU.H
code from runmenu is on menu.c
initialization of structure is on app.h
andromeda92
Member
Posts: 62
Joined: Wed Apr 17, 2024 1:05 am

Re: compounds literal and c99

Post by andromeda92 »

my .map file and .sym file with error programm
You do not have the required permissions to view the files attached to this post.
andromeda92
Member
Posts: 62
Joined: Wed Apr 17, 2024 1:05 am

Re: compounds literal and c99

Post by andromeda92 »

May be the problem is from static initialization of flexible array member.
Only gcc permit this.
User avatar
dom
Well known member
Posts: 2194
Joined: Sun Jul 15, 2007 10:01 pm

Re: compounds literal and c99

Post by dom »

Thanks so much for the source code - it fails in the same way under zxcc which eliminates a lot of variables.
The downside being that the size can't be determined, so it really only works with global structures.
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.

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.
andromeda92
Member
Posts: 62
Joined: Wed Apr 17, 2024 1:05 am

Re: compounds literal and c99

Post by andromeda92 »

Thanks for investing time on my problem, I will test this.
andromeda92
Member
Posts: 62
Joined: Wed Apr 17, 2024 1:05 am

Re: compounds literal and c99

Post by andromeda92 »

it work now passing pointer to function,
Thank you very much.
andromeda92
Member
Posts: 62
Joined: Wed Apr 17, 2024 1:05 am

Re: compounds literal and c99

Post by andromeda92 »

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;

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} };
All work great.
Post Reply