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

Variables overlap with PCD 4.092

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







Variables overlap with PCD 4.092
PostPosted: Fri May 08, 2009 7:41 am     Reply with quote

I'm using a CCS PCD 4.092 with a dsPIC33FJ256GP710.

When I call a function, the parameter variable in the called function will overlap one local variable in calling function.

Ex,
Code:
void do_check_temperature()
{
     unsigned int16 value = 0;

     value = 0xff;

     set_module_temp_ok(true);

     return value;
}


Code:
void set_module_temp_ok(bool temp_ok)
{
   temp_in_range = temp_ok;
}

In main.sym


8A8-8A9 do_check_temperature.value
8A8-8A9 handleSSDReq.message
8A8-8AB sendTempCounters.overtemp_cnr
8A8-8A9 handleVoltageReq.VBUS1_V
8A8-8A9 handleDaisyReq.message
8A8-8A9 handleConfigModuleReq.message
8A8-8A9 handleSetTempReportIntReq.message
8A8-8DD sendStopModuleRpy.message
8A8-8DD sendFirmwareUpgreadeRpy.message
8A8-8DD sendSimInfoMessage.message
8A8-8A9 handleSetLedWarning.message
8A8-8A9 handleSetTemplimitReq.message
8A8-8A9 handleResetModuleReq.message
8A8-8DD sendPong.message
8A8 sendFirmwareInfo.minor
8A8-8DD sendSyncReq.message
8A8-8A9 handleTempReq.temperature
8A9 set_module_temp_ok.temp_ok

What can I do about this?
Ttelmah
Guest







PostPosted: Fri May 08, 2009 3:14 pm     Reply with quote

The reason here, is that CCS, will try to re-use memory space, if a function has finished with it.
Your first function, has a void return type. CCS, does not support the 'late typed' style of void, from ANSI, but treats void as null. Therefore the compiler sees the function, as having no further use for the varable, and re-uses the space. Change the do_check_temperature declaration to int16, and the overlap should disappear.
However also study how many problems there are with the DSPIC's and CCS at present.....

Best Wishes
Aneben
Guest







PostPosted: Mon May 11, 2009 12:40 am     Reply with quote

Hi there,

Sorry, the code wasn't correct.
Consider this instead:

Code:
void do_check_temperature()
{
     unsigned int16 value = 0;

     value = 0xff;

     set_module_temp_ok(true);

     if(value = 0xff)
         printf("blopp");

}



Code:
void set_module_temp_ok(bool temp_ok)
{
    temp_in_range = temp_ok;
}



In main.sym

8A8-8A9 do_check_temperature.value
8A8-8A9 handleSSDReq.message
8A8-8AB sendTempCounters.overtemp_cnr
8A8-8A9 handleVoltageReq.VBUS1_V
8A8-8A9 handleDaisyReq.message
8A8-8A9 handleConfigModuleReq.message
8A8-8A9 handleSetTempReportIntReq.message
8A8-8DD sendStopModuleRpy.message
8A8-8DD sendFirmwareUpgreadeRpy.message
8A8-8DD sendSimInfoMessage.message
8A8-8A9 handleSetLedWarning.message
8A8-8A9 handleSetTemplimitReq.message
8A8-8A9 handleResetModuleReq.message
8A8-8DD sendPong.message
8A8 sendFirmwareInfo.minor
8A8-8DD sendSyncReq.message
8A8-8A9 handleTempReq.temperature
8A9 set_module_temp_ok.temp_ok
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon May 11, 2009 1:09 am     Reply with quote

Quote:
if(value = 0xff)

should be
Quote:
if(value == 0xff)

If the problem persists with meaningful code, it's supposed to be a PCD bug.
Ttelmah
Guest







PostPosted: Mon May 11, 2009 3:10 am     Reply with quote

What is posted, is again perfectly reasonable action.
The optimiser looks at what you are doing.
The 'temp_ok' variable, is only ever read, and in current 'C' useage, corresponds to the bottom bit of the value being passed (historically, C in the past, did a conversion from a int16, to a bit, by perfroming a logic test on the whole variable, but current - ANSI compatible _ conversion, is done by simply testing the bottom bit). Since the bit is never written, the compiler just makes the local variable map to the same place as the bottom bit of the source variable.
The optimiser is trying to minimise data movement, that is not needed.

Best Wishes
Guest








PostPosted: Mon May 11, 2009 3:47 am     Reply with quote

Thanks for trying to help.

It seems like my examples aren't the best.

Consider this:

Code:
void do_check_temperature()
{
     unsigned int16 value = 0;

     //Read value from AD
     value = readAD();

     if(value >= 100)
            set_module_temp_ok(true);

     if(value < 100)
         printf("Temp to high");
}


Code:
void set_module_temp_ok(bool temp_ok)
{
    temp_in_range = temp_ok;
}


In main.sym


8A8-8A9 do_check_temperature.value
8A8-8A9 handleSSDReq.message
8A8-8AB sendTempCounters.overtemp_cnr
8A8-8A9 handleVoltageReq.VBUS1_V
8A8-8A9 handleDaisyReq.message
8A8-8A9 handleConfigModuleReq.message
8A8-8A9 handleSetTempReportIntReq.message
8A8-8DD sendStopModuleRpy.message
8A8-8DD sendFirmwareUpgreadeRpy.message
8A8-8DD sendSimInfoMessage.message
8A8-8A9 handleSetLedWarning.message
8A8-8A9 handleSetTemplimitReq.message
8A8-8A9 handleResetModuleReq.message
8A8-8DD sendPong.message
8A8 sendFirmwareInfo.minor
8A8-8DD sendSyncReq.message
8A8-8A9 handleTempReq.temperature
8A9 set_module_temp_ok.temp_ok

The readAD function will get a value from the AD that can anything between 0-4095.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon May 11, 2009 2:02 pm     Reply with quote

I tried to achieve a similar behaviour, but I didn't succed in overlaying do_check_temperature.value or another variable, that has to be persistent during set_module_temp_ok() execution with set_module_temp_ok.temp_ok. I also used PCD V4.092. I guess, there must be something special in your application, not visable from the shown code, a setting different from compiler default (e.g. in optimization level) or another special condition. Have you tried, to extract a minimal example from your code, that reproduces the problem?

It may be the case, that you can't reproduce it after removing part of your application, but then you possibly get insights in the conditions that are necessary to generate it.
Guest








PostPosted: Tue May 12, 2009 6:09 am     Reply with quote

Okey, thanks for your time.

I'll try that later.
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