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 CCS Technical Support

floats in eeprom

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







floats in eeprom
PostPosted: Sat Feb 03, 2007 10:34 am     Reply with quote

float get_float(long int n)
{
int i,y;
float data_f=0;
printf("%2X\n\r",n);
for(i=0;i<4;i++){
*(&data_f+i)=read_eeprom(i+n);
y=read_eeprom(i+n);
printf("%2X\n\r",y);
}
printf("%f\n\r",data_f);
return (data_f);
} [/code]

hello,
using above code. diregard the printf statements.debug only. if the eeprom contains 0x7f,0x00,0x00,0x00 this module returns decimal 127. It should be decimal 1. this code has worked for a year. I recently upgraded to the most recent version of PCH and this portion of code does not work.
this is on a PIC18F2620.
any help would be graetly appreciated
thanks
eaton[/code]
hwk
Guest







code that worked
PostPosted: Sat Feb 03, 2007 12:58 pm     Reply with quote

float get_float(long int n)
{
int i,y;
float data_f=0;
int *p;
p=&data_f;

for(i=0;i<4;i++){
//y=read_eeprom(i+n);
//*(&data_f+i)=read_eeprom(i+n);
*(p+i)=read_eeprom(i+n);
}
return (data_f);
}
this finally worked. is there some subtle difference in the compiler that I'm missing. the line //*(&data_f+i)=read_eeprom(i+n); should work i think. the line *(p+i)=read_eeprom(i+n); is essentialy the same and it does work. Can anybody provide an explanation?
thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Feb 03, 2007 1:19 pm     Reply with quote

CCS recently made a change in the compiler operation that affects your
code. See the versions page here:
http://www.ccsinfo.com/devices.php?page=versioninfo
Here is the change:
Quote:

4.021 The & unary operator by default no longer returns a generic (int8 *)


This means that to make your code work, you must cast the address
to a char pointer:
Quote:
*((char *)(&data_f) + i) = read_eeprom(i+n);
hwk
Guest







PostPosted: Sat Feb 03, 2007 3:01 pm     Reply with quote

thanks PCM
that explains it. Insidious little bug. I have to make more time for reading the version changes.
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