Searching \ for '[pic]:struct+pointer' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'struct+pointer'.

Exact match. Not showing close matches.
PICList Thread
'[pic]:struct+pointer'
2002\02\26@033529 by Also-Antal Csaba

flavicon
face
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)

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;

int light;
int optimum;
int close_time;
}ship;

typedef struct {
const ship * numb;
}blokk;



static bank3 ship ship1 = 111,210,0,400,40,-123,
550,1000,10,100,40,80,81,150,0, 134,300,4000;

etc...

const blokk house[] ={ & ship1,
& ship2,
& ship3,
& ship4,
& ship5,
& ship6,
& ship7,
& ship8
};

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\02\26@042632 by Carlos Ojea

flavicon
face
>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


2002\02\26@052527 by Also-Antal Csaba

flavicon
face
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


2002\02\26@060403 by Peter Onion

flavicon
face
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.

Peter.


{Quote hidden}

----------------------------------
E-Mail: Peter Onion <spam_OUTponionTakeThisOuTspamsrd.bt.co.uk>
Date: 26-Feb-02
Time: 10:50:21

This message was sent by XFMail
----------------------------------

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\02\26@081713 by michael brown

flavicon
face
----- 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.

p->temperature

{Quote hidden}

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\02\26@085628 by Sergio Masci

picon face
> > 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.
>
> p->temperature
>
> >
> > Why???

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


2002\02\26@102342 by Also-Antal Csaba

flavicon
face
> Note the use of the "->" operator.

I tryed, before wrote here, the diference is the error message :(.

> 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.

I this so. The next code is iron ring from wood, at least but work:

switch(ship_no){

       case 0: ship1.temperature = tempe;
               ship1.tem_cal     = calib;
               break;
       case 1: ship2.temperature = tempe;
               ship2.tem_cal     = calib;
               break;
       case 2: ship3.temperature = tempe;
               ship3.tem_cal     = calib;
               break;
       case 3: ship4.temperature = tempe;
               ship4.tem_cal     = calib;
               break;
       case 4: ship5.temperature = tempe;
               ship5.tem_cal     = calib;
               break;
       case 5: ship6.temperature = tempe;
               ship6.tem_cal     = calib;
               break;
       case 6: ship7.temperature = tempe;
               ship7.tem_cal     = calib;
               break;
       case 8: ship8.temperature = tempe;
               ship8.tem_cal     = calib;
               break;
       }
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


2002\02\26@103222 by Also-Antal Csaba

flavicon
face
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


2002\02\26@103231 by Lawrence Lile

flavicon
face
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.

--Lawrence

{Original Message removed}

2002\02\26@103829 by Also-Antal Csaba

flavicon
face
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)

This correct, but dont work.

varibles.c: 107: pointer required (error)
varibles.c: 107: pointer required (error)
varibles.c: 107: attempt to modify const object (warning)

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


2002\02\26@104035 by Bond, Peter

flavicon
face
> 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


2002\02\26@105449 by Sergio Masci

picon face
----- Original Message -----
From: Also-Antal Csaba <.....antalcsKILLspamspam@spam@MAIL.MATAV.HU>
To: <PICLISTspamKILLspamMITVMA.MIT.EDU>
Sent: Tuesday, February 26, 2002 3:30 PM
Subject: Re: [pic]:struct+pointer


{Quote hidden}

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


2002\02\26@111341 by Michael Rigby-Jones

flavicon
face
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.

Regards

Mike

> {Original Message removed}

2002\02\26@111518 by Bob Ammerman

picon face
If you have a structure 's' you access its members like this:

   s.onemember
   s.anothermember

When you have a pointer 'p' to a structure you access the members of the
structure like this:

   p->onemember
   p->anothermember

Or, if you like more obscure syntax:

   (*p).onemember
   (*p).anothermember

Or, for the truly strange:

   p[0].onemember
   p[0].anothermember

Bob Ammerman
RAm Systems

{Original Message removed}

2002\02\26@111524 by michael brown

flavicon
face
Lawrence asks,

> 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


2002\02\26@112000 by Bob Ammerman

picon face
int          * pi;

int const *    pci;
 - or -
const int * pci;

int *const     cpi;

int const * const  cpci;
   - or -
const int * const cpci;

pi is a pointer to integer: both the pointer and the value it points to can
be changed.

pci is a pointer to a constant integer: the value it points to can't be
changed, but the pointer itself can be.

cpi is a constant pointer to integer. the value it points to can be changed,
but the pointer itself can't be.

cpci is a constant pointer to constant integer: neither the point or the
value it points to can be changed.

Bob Ammerrman
RAm Systems


{Original Message removed}

2002\02\26@122253 by Also-Antal Csaba

flavicon
face
> > > > > 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


2002\02\26@131852 by David Koski

flavicon
face
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.

David Koski
.....davidKILLspamspam.....KosmosIsland.com

On Tue, 26 Feb 2002 09:33:08 +0100
Also-Antal Csaba <EraseMEantalcsspam_OUTspamTakeThisOuTMAIL.MATAV.HU> wrote:

{Quote hidden}

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\02\27@011218 by Also-Antal Csaba

flavicon
face
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.

htsoft picc

udv
Csaba

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2002\02\27@011845 by Also-Antal Csaba

flavicon
face
> 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

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2002\02\27@032322 by Michael Rigby-Jones

flavicon
face
{Quote hidden}

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.

Regards

Mike

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2002\02\27@044318 by Also-Antal Csaba

flavicon
face
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.

Thanks all help.

udv
Csaba



{Quote hidden}

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


More... (looser matching)
- Last day of these posts
- In 2002 , 2003 only
- Today
- New search...