[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 to understand / ge
From: |
larry barello |
Subject: |
RE: [avr-gcc-list] A couple GCC warnings I would like to understand / get rid of... |
Date: |
Thu, 22 Jan 2009 10:17:07 -0700 |
the compiler is complaining because you have an extra or a missing "const"
in your structure definitions. There is a mismatch between your flash
declaration and the type of pointer within your struct. Probably adding a
const keyword to the pointer within your struct and removing the const in
your declaration will fix the problems.
-----Original Message-----
From: address@hidden
[mailto:address@hidden On Behalf Of
Vincent Trouilliez
Sent: Thursday, January 22, 2009 8:20 AM
To: address@hidden
Subject: [avr-gcc-list] A couple GCC warnings I would like to understand /
get rid of...
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
address@hidden
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
- [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 <=
- 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, 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..., Weddington, Eric, 2009/01/24