When I use this code:
temp = (*house[index].numb).temperature;
the picc make good result.
But if I want change the value of temperature in the struct, with this:
(*house[index].numb).temperature=temp;
I get this message:
varibles.c: 108: Can't generate code for this expression (error)
This code is work:
ship1.temperature = 999;
and this not:
cost ship * p;
p=&ship1;
(*p).temperature=123;
the error message is same.
Why???
typedef struct {
char address;
int temperature;
char adjust;
char max_alarm;
char min_alarm;
signed char tem_cal;
int relhum;
int pwm;
char spay_time;
char spay_dlay;
char min_hum;
char max_hum;
char str_time;
char stp_time;
signed char rh_cal;
>But if I want change the value of temperature in the struct, with this:
>(*house[index].numb).temperature=temp;
>I get this message:
>varibles.c: 108: Can't generate code for this expression (error)
Did you try just without the '*'?:
(house[index].numb).temperature = temp;
-- http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads
Carlos Ojea wrote:
>
> >But if I want change the value of temperature in the struct, with this:
> >(*house[index].numb).temperature=temp;
> >I get this message:
> >varibles.c: 108: Can't generate code for this expression (error)
>
> Did you try just without the '*'?:
> (house[index].numb).temperature = temp;
That is not work, because this expresion need a pointer. The
house[0].numb array contains the address of the ship1 stuct.
udv
Csaba
-- http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads
On 26-Feb-02 Also-Antal Csaba wrote:
> Hi,
>
> When I use this code:
> temp = (*house[index].numb).temperature;
> the picc make good result.
>
> But if I want change the value of temperature in the struct, with this:
> (*house[index].numb).temperature=temp;
> I get this message:
> varibles.c: 108: Can't generate code for this expression (error)
Your definitions and typedefs seem more complex than is needed, but I think
I've worked them out.
house is an array of blokks
so house[index] is a blokk
a blokk contains a single element numb which is a pointer to a ship
so house[index].numb is a pointer to a ship
so house[index].numb->temperature is the temperature member in a ship
Note the use of the "->" operator.
Try that and see it is works. It should be equiv to the expression you used
but maybe there is a compiler bug or restriction.
----- Original Message -----
From: "Also-Antal Csaba"
> But if I want change the value of temperature in the struct, with this:
> (*house[index].numb).temperature=temp;
> I get this message:
> varibles.c: 108: Can't generate code for this expression (error)
Doesn't picc allow you to say:
house[index]->numb->temperature=temp
(I think this is correct, but you have a complex setup)
> This code is work:
> ship1.temperature = 999;
>
> and this not:
>
> cost ship * p;
> p=&ship1;
> (*p).temperature=123;
> the error message is same.
You can read from but not write to a const location.
const meens constant, unchanging. Declaring a const
pointer meens that it points to something which must
not be changed.
Sergio Masci wrote:
>
> > > cost ship * p;
>
> is this cost actually const?
>
> You can read from but not write to a const location.
> const meens constant, unchanging. Declaring a const
> pointer meens that it points to something which must
> not be changed.
>
> > > p=&ship1;
> > > (*p).temperature=123;
> > > the error message is same.
The p pointer is const, but the &ship1 expression is the address of the
ship1 variable. (*p).temperature=123; is point to the ship1.temperature
varible. So the ship1.temperature=123; and (*p).temperature=123; is must
be equal. When i read from work, when write not, this looks like a bug.
udv
Csaba
-- http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads
OK, what exactly does this "->" operator accomplish? My book says it is a
"structure pointer operator", which might as well say it was a Left Handed
Metric 1" Macedonian Rubber-headed Fiddle Wrench and I'd still be none the
wiser.
michael brown wrote:
>
> ----- Original Message -----
> From: "Also-Antal Csaba"
> > But if I want change the value of temperature in the struct, with this:
> > (*house[index].numb).temperature=temp;
> > I get this message:
> > varibles.c: 108: Can't generate code for this expression (error)
>
> Doesn't picc allow you to say:
>
> house[index]->numb->temperature=temp
>
> (I think this is correct, but you have a complex setup)
> OK, what exactly does this "->" operator accomplish? My book
> says it is a
> "structure pointer operator", which might as well say it was
> a Left Handed
> Metric 1" Macedonian Rubber-headed Fiddle Wrench and I'd
> still be none the
> wiser.
Shorthand, effectively.
When working with a struct, referencing an element of a struct us done using
dot notation.
i.e.
struct mystruct s;
s.element
When working with a pointer to a structure -
struct mystruct *s;
to access the element, you can use...
(*s).element
or, preferably
s-> element
Reference - K&R, 6.2 (p131 in my edition)
I think I have the manual for the rubber-headed fiddle wrench somewhere,
too.
HTH
Peter
This email, its content and any attachments is PRIVATE AND CONFIDENTIAL to
TANDBERG Television. If received in error please notify the sender and
destroy the original message and attachments.
-- http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads
> Sergio Masci wrote:
> >
> > > > cost ship * p;
> >
> > is this cost actually const?
> >
> > You can read from but not write to a const location.
> > const meens constant, unchanging. Declaring a const
> > pointer meens that it points to something which must
> > not be changed.
> >
> > > > p=&ship1;
> > > > (*p).temperature=123;
> > > > the error message is same.
>
> The p pointer is const, but the &ship1 expression is the address of the
> ship1 variable. (*p).temperature=123; is point to the ship1.temperature
> varible. So the ship1.temperature=123; and (*p).temperature=123; is must
> be equal. When i read from work, when write not, this looks like a bug.
no the pointer is not const, it is a pointer to a const.
to get a const pointer you would write:
ship * const p;
Regards
Sergio
-- http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads
It depends on the declaration, but a "const pointer" would normaly be
construed as a pointer that can cannot be modifed, pointing to an object
that may or may not be constant.
const int *myptr is a non-constant pointer to a constant int.
int *const myptr is constant pointer to a non-constant int.
const int *const myptr is a constant pointer to a constant int.
> OK, what exactly does this "->" operator accomplish? My book says it is a
> "structure pointer operator", which might as well say it was a Left Handed
> Metric 1" Macedonian Rubber-headed Fiddle Wrench and I'd still be none the
> wiser.
Say you have a structure pointer "p" that points to a structure of type
"pixel_location" that contains two elements "x" and "y". You can refer to
the elements by using "(*p).x" if that floats your boat. (its kind of a
hassle to do it that way, because you HAVE to add the parenthesis) The
easier (and arguably more clear) way to do it is to use the shorthand
notation of -> eg. "p->x" or "p->y"
michael
-- http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads
> > > > > p=&ship1;
> > > > > (*p).temperature=123;
> > > > > the error message is same.
> >
> > The p pointer is const, but the &ship1 expression is the address of the
> > ship1 variable. (*p).temperature=123; is point to the ship1.temperature
> > varible. So the ship1.temperature=123; and (*p).temperature=123; is must
> > be equal. When i read from work, when write not, this looks like a bug.
>
> no the pointer is not const, it is a pointer to a const.
No, the p pointer is pointer to _variable_. But placed in the rom, so
this realy constant :).
udv
Csaba
-- http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads
What compiler are you using? As of a couple of years ago, the CCS complier had
proven to not handle moderately complex indirection very well sometimes. In one
case, it silently produced bad code.
David Koski wrote:
>
> Hello,
>
> What compiler are you using? As of a couple of years ago, the CCS complier had
> proven to not handle moderately complex indirection very well sometimes. In one
> case, it silently produced bad code.
> -----Original Message-----
> From: Also-Antal Csaba [SMTP:antalcsspam_OUTMAIL.MATAV.HU]
> Sent: Wednesday, February 27, 2002 6:16 AM
> To: @spam@PICLISTKILLspamMITVMA.MIT.EDU
> Subject: Re: [pic]:struct+pointer
>
> > no the pointer is not const, it is a pointer to a const.
> >
> > to get a const pointer you would write:
> >
> > ship * const p;
>
> I was thinking about it, you have right. But this code give me a linker
> error, so thats all.
>
> main.obj:105:Fixup overflow in expression (loc 0x3EC (0x3EA+2), size 1,
> value 0x190) (error)
> main.obj:105:Fixup overflow in expression (loc 0x3EE (0x3EA+4), size 1,
> value 0x1A8) (error)
> main.obj:105:Fixup overflow in expression (loc 0x3F0 (0x3EA+6), size 1,
> value 0x1C0) (error)
> main.obj:105:Fixup overflow in expression (loc 0x3F2 (0x3EA+8), size 1,
> value 0x110) (error)
> main.obj:105:Fixup overflow in expression (loc 0x3F4 (0x3EA+10), size 1,
> value 0x128) (error)
> main.obj:105:Fixup overflow in expression (loc 0x3F6 (0x3EA+12), size 1,
> value 0x140) (error)
> main.obj:105:Fixup overflow in expression (loc 0x3F8 (0x3EA+14), size 1,
> value 0x158) (error)
> main.obj:105:Fixup overflow in expression (loc 0x3FA (0x3EA+16), size 1,
> value 0x1D8) (error)
>
> udv
> Csaba
>
This is caused by not declaring the pointer bank correctly. As your Ship
variables are in bank3, you have to tel the compiler you want your pointer
to access bank3.
From you original example try:
typedef struct {
bank3 ship * const numb;
}blokk;
This is a major stumbling block when dealing with pointers in a banked
architecture like the PICs.
Note also that in your original example there will not be enough room in
bank3 for 8 instances of your 'ship' structure.
The original problem is, one bank can't store the all ship variables.
Because of this I can't use one array to store the all varibles in one.
I have two choice:
1. use two independent array, one for a bank2 and one for a bank3
2. Write a "virtual" array whith pointers to handle, two banks together.
So I can't use your theory because is some as point one.
> This is caused by not declaring the pointer bank correctly. As your Ship
> variables are in bank3, you have to tel the compiler you want your pointer
> to access bank3.
>
> >From you original example try:
>
> typedef struct {
> bank3 ship * const numb;
> }blokk;
>
> This is a major stumbling block when dealing with pointers in a banked
> architecture like the PICs.
> Note also that in your original example there will not be enough room in
> bank3 for 8 instances of your 'ship' structure.