CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug Reports on this forum. Send them to support@ccsinfo.com

#locate error with typedef structure initializing.

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
raza741



Joined: 16 Oct 2019
Posts: 2

View user's profile Send private message

#locate error with typedef structure initializing.
PostPosted: Wed Oct 16, 2019 9:34 pm     Reply with quote

Hi Everyone,

I am using IDE version 5.030, with dsPic 33EP512MU814.

The code below is not compiling correctly

Code:

static unsigned int16 senPrsData[3]={0,200,800};
#locate senPrsData = 0x1514
#define pressure_is_on      senPrsData[0]
#define prs_alarm_min       senPrsData[1]
#define prs_alarm_max       senPrsData[2]


Code:

typedef struct _Sensor_Detection
{
   unsigned int16 *senEnable;
   signed int16 *senMaxThreshold;
   signed int16 *senMinThreshold;
} Sensor_Detection;


Code:

static Sensor_Detection senPumpPres = {&pressure_is_on, &prs_alarm_max, &prs_alarm_min};


So what is happening is that when I remove

Code:
#locate senPrsData = 0x1514


it compiles correctly and I get the correct address in the structure "senPumpPres", address which are actually compiler it self assigned.

But when I use "#locate", it assign the correct addresses to senPrsData[] array, starting from 0x1514, but all the members in structure "senPumpPres" are assigned the same value which is 0x1514. where as it should assign 0x1514, 0x1516 and 0x1518.

Is there any issue with the compiler or am I doing something completely wrong.

Sorry if I did not follow the forum policies correctly. Thanks In advance.
Raza
Ttelmah



Joined: 11 Mar 2010
Posts: 15285

View user's profile Send private message

PostPosted: Thu Oct 17, 2019 1:40 am     Reply with quote

Seriously, big red flag. 5.030!...
What is happening, is the compiler is taking the address of the variable,
and not the sub component, but then doesn't know how to add the offset
to reach the required part.
Ugh.
It is fixed a few versions later.

With 5.040:
Code:

00220:  MOV     #1514,W4
00222:  MOV     W4,1000
00224:  MOV     #1518,W4
00226:  MOV     W4,1002
00228:  MOV     #1516,W4
0022A:  MOV     W4,1004


As you can see, correctly placing the pointers to the three different
locations.
It looks as if the act of 'locating' the variable, is making the compiler
'forget' it's array nature.
You can (of course), cheat:

static Sensor_Detection senPumpPres = {senPrsData, senPrsData+1, senPrsData+2};

No. Just tested, and on your compiler this does the same thing:
Code:

00220:  MOV     #1514,W4
00222:  MOV     W4,1000
00224:  MOV     #1514,W4
00226:  MOV     W4,1002
00228:  MOV     #1514,W4
0022A:  MOV     W4,1004


It seems to be fundamentally 'hiccuped', when handling pointers to
a #located variable.

Only workround I have found is to work 'through' a variable. So:
Code:

const byte * locn = senPrsData;

static Sensor_Detection senPumpPres = {locn, locn+2, locn+4};


Correctly generates the required addresses....
raza741



Joined: 16 Oct 2019
Posts: 2

View user's profile Send private message

PostPosted: Thu Oct 17, 2019 3:24 pm     Reply with quote

Thanks for you help Ttelmah. Smile

We used to update the compiler regularly before and what ends up happening was it sometimes introduces new bugs which was then hard to find that if any other part of the code get effected. So we stopped updating after 5.030.

I guess I have to do the workaround as you suggested. As it's still better than initializing every element of the structure one by one.
Ttelmah



Joined: 11 Mar 2010
Posts: 15285

View user's profile Send private message

PostPosted: Thu Oct 17, 2019 11:23 pm     Reply with quote

Why not just keep multiple versions?. I have probably 100 versions of
the compiler all installed. When working on code, I note as part of the
comments at the top of the program, the compiler version being used.
Then when a new version is launched, I try and see if everything still
works. If it does I update the version to use.
I've had programs that refused to update between versions on about
three occasions. In each case a little work later gave me a version
that became compatible. Problems like this were quite common with
V5, and particularly the first few compilers after this launched. The newer
compilers do have a lot of new features and quite a few improvements,
so it is worth considering trying at least one update.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group