Hi,
I am having a couple GCC warning I would like to understand and
hopefully clear with a graceful modification of my code, if anyone can
help...
Basically it's to do with the structures I put in Flash, and the
pointers to these structures (which are themselves located in said
structures).
When I initialize the structure with constant data, GCC coughs about
the field where I store the pointer.
Then later in the code, when trying to retrieve/read that pointer and
use it, I also get a warning.
It has to be said that GCC actually understands what I want to do,
because it stored and retrieved the correct pointer value, and my
program works as expected. It's just that these warning are annoying
and of course, maybe I did do a mistake in the syntax, and that would be
the opportunity to learn a little something new today..
#1 warning: when storing pointer in Flash
------------------------------------------
Pointer is stored in structure "menu_main", and points to "menu_sub"
(structure of the same type).
//target structure
const struct TMenu menu_sub PROGMEM = {
....
};
//struct holding the pointer
const struct TMenu menu_main PROGMEM = {
...
{.... , &menu_sub,...}, <-------WARNING
}
};
The warning is:
"warning: initialization from incompatible pointer type"
I don't understand why it's incompatible. I the structure is define as
this:
struct TMenu;
struct TMenuItem {
char text[20];
struct Tmenu *ptr;
void (*fptr)();
};
the pointer ptr is declared as a pointer to a structure of type TMenu,
and of course I initialize it with the address of such a structure
(&menu_sub), so... where is the incompatibility ? :-/
#2 warning: when retrieving/reading pointer from Flash
------------------------------------------------------
//----------------------------------
// declare pointers of same type as found in struture,
// in order to read them from flash
void (*FncPtr)();
const struct TMenu *SubPtr;
FncPtr = pgm_read_word( & (p->items[cursor].fptr) );
SubPtr = pgm_read_word( & (p->items[cursor].ptr) );
//-------------------------------------
I get a identical warning for each of these lines/reads :
"warning: assignment makes pointer from integer without a cast"
Here for a change, I think I can, agree with GCC, since pgm_read_word
returns an integer, but what's the syntax to turns that back into the
pointer it once was ?!
Something like that ?
FncPtr = ( void (*FncPtr)() )pgm_read_word( & (p->items[cursor].fptr) );
and similarly:
SubPtr = (*SubPtr)pgm_read_word( & (p->items[cursor].ptr) );
Tried, doesn't work...
A cyber beer offered to anyone with the answer :-)
Regards,
--
Vince, still at the very bottom of the learning curve, brrr...
_______________________________________________
AVR-GCC-list mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list