Some issue with pointers




Hello,

I need some help to understand what I'm doing :)

I'm writing code for an embedded system and I need to create a navigable menu system. I'm going to use these structures:

typedef struct {
char *name[2];
int type;
int num_param;
void *ptr;
} menuitem_t;

typedef struct {
char *name[2];
int num_items;
menuitem_t *items;
} menu_t;


The latter defines each menu or submenu with a name, a number of items and a pointer to the items structure.

The former defines each menu item with a name, a type (see below) the number of parameters - if any - and finally a generic pointer (see below again).

In this way I can generate menus of any complexity and very flexible. The void pointer should point to another menu_t struct if the item leads to a submenu, to an array if it leads to a parameter list. But it could also leads to a function if the selection of this item needs an action to be executed.

Actually I have two questions:

1) I can't cast correctly the void *ptr. Let's say I want to access to:

char *par[] = {"First", "Second"};

ot invoke:

void myfunc();

Please, may you help me to understand how to cast and then to use that pointer in these cases?

2) It would be nice if I can know the path the user is following. For example:

mainmenu -> seconditem -> firstitem

where each of these entities are menu_t structs.
How would you implement such a dynamic path?

Thank you and I apologize for my poor English
Marco / iw2nzm
.



Relevant Pages

  • Re: invalid pointer adress
    ... >> pointer causes the program to exit with a core dump. ... struct s2{void *p;}; ... int leseExterneHinweise_masch_storno ... typedef struct s_AusdatFeldbeschreibung ...
    (comp.lang.c)
  • Re: A C Adventure: your comments are welcome
    ... void * usrRightSegment; ... That is a string is a binary tree of segments, ... struct inside a struct either as the thing itself or as a pointer ... because C makes it easy to change pointer type. ...
    (comp.lang.c)
  • Re: Some issue with pointers
    ... typedef struct { ... void *ptr; ... and a pointer to the items structure. ...
    (comp.lang.c)
  • Re: Pointer to a member variable in a struct without dereferencing the member
    ... I have the below struct and I need to access the pointer to the "void ... * data" member without actually dereferencing the member variable. ...
    (comp.lang.c.moderated)
  • Re: function pointer casting
    ... Here you say the second member of the struct is a function pointer ... apparently is not the same as pointer to void. ... implied assignment of the argument to the parameter. ...
    (comp.lang.c)