[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [avr-gcc-list] A couple GCC warnings I would like tounderstand/ get
From: |
Weddington, Eric |
Subject: |
RE: [avr-gcc-list] A couple GCC warnings I would like tounderstand/ get rid of... |
Date: |
Sat, 24 Jan 2009 17:46:35 -0700 |
> -----Original Message-----
> From:
> address@hidden
> [mailto:address@hidden
> org] On Behalf Of Vincent Trouilliez
> Sent: Saturday, January 24, 2009 5:25 PM
> To: address@hidden
> Subject: Re: [avr-gcc-list] A couple GCC warnings I would
> like tounderstand/ get rid of...
>
> > ... where I initialize a pointer with "&dummy_func"
>
> errata, I meant &menu_sub not &dummy_func of course...
>
I'd like to point something out.
The structure type definitions are this:
struct TMenuItem {
char text[20];
const struct Tmenu *ptr;
void (*fptr)();
};
struct TMenu {
uint8_t nb;
char title[21];
const struct TMenuItem items[];
};
Your original data structure initialization is this:
struct TMenu menu_main PROGMEM = {
6,
"___Main Menu________",
{
{"Item 1 ",&menu_sub,NULL},
{"Item 2 ",&menu_sub,NULL}
}
};
Which means that you have the NULL and the &menu_sub *reversed* according to
your data structure layout, and then on top of this your &menu_sub is the
*wrong data*! The structure is looking for a pointer to a function, and you are
giving it a pointer to another struct TMenu type.
This is why it needs to be changed to this:
struct TMenu menu_main PROGMEM = {
6,
"___Main Menu________",
{
{"Item 1 ",NULL,&dummy_fnc},
{"Item 2 ",NULL,&dummy_fnc}
}
};
The other two lines that I changed, were these:
FncPtr = (void (*)(void))(pgm_read_word( & (p->items[0].fptr) ));
SubPtr = (const struct TMenu *)(pgm_read_word( & (p->items[0].ptr) ));
The reason is that the pgm_read_word macro returns a uint16_t type which you
are then assigning to variables that are pointer types (pointing to two
different things). All you needed to do was to typecast the result of
pgm_read_word() (as I did above) to match the type of the variable that you are
assigning to.
HTH,
Eric Weddington
- [avr-gcc-list] A couple GCC warnings I would like to understand / get rid of..., Vincent Trouilliez, 2009/01/22
- RE: [avr-gcc-list] A couple GCC warnings I would like to understand / get rid of..., larry barello, 2009/01/22
- Re: [avr-gcc-list] A couple GCC warnings I would like to understand / get rid of..., Vincent Trouilliez, 2009/01/24
- Re: [avr-gcc-list] A couple GCC warnings I would like to understand / get rid of..., Vincent Trouilliez, 2009/01/24
- RE: [avr-gcc-list] A couple GCC warnings I would like to understand/ get rid of..., Weddington, Eric, 2009/01/24
- Re: [avr-gcc-list] A couple GCC warnings I would like to understand/ get rid of..., Vincent Trouilliez, 2009/01/24
- RE: [avr-gcc-list] A couple GCC warnings I would like tounderstand/ get rid of..., Weddington, Eric, 2009/01/24
- Re: [avr-gcc-list] A couple GCC warnings I would like tounderstand/ get rid of..., Vincent Trouilliez, 2009/01/24
- Re: [avr-gcc-list] A couple GCC warnings I would like to understand/ get rid of..., Vincent Trouilliez, 2009/01/24
- RE: [avr-gcc-list] A couple GCC warnings I would like tounderstand/ get rid of...,
Weddington, Eric <=
- Re: [avr-gcc-list] A couple GCC warnings I would like tounderstand/ get rid of..., Vincent Trouilliez, 2009/01/24
- RE: [avr-gcc-list] A couple GCC warnings I would like tounderstand/get rid of..., Weddington, Eric, 2009/01/24
- Re: [avr-gcc-list] A couple GCC warnings I would like tounderstand/get rid of..., Vincent Trouilliez, 2009/01/24
- Re: [avr-gcc-list] A couple GCC warnings I would like tounderstand/get rid of..., Vincent Trouilliez, 2009/01/24
- Re: [avr-gcc-list] A couple GCC warnings I would like tounderstand/get rid of..., Vincent Trouilliez, 2009/01/24