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

float in a structure problem

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







float in a structure problem
PostPosted: Wed Jul 31, 2002 7:58 am     Reply with quote

Dear,

PCWH v3.103 and PIC18F452

I have this structure:

struct
{
char text_eng [DIM1];
float value_min;
float value_max;
float value_default;
float value;
char value_unit [DIM3];
} menu [DIM2];


main
{
int8 menu_cnt = 0;

menu[menu_cnt].value = 12.34567;
menu[menu_cnt].value += 0.05;
}

(the code is only to describe the problem, not running)

the allocation of 12.34567 is working, but after the addition of 0.05 the value in menu[menu_cnt].value has not changed, it
is still 12.34567

Instead of menu[menu_cnt].value I have tried a float variable that is not defined in the structure and it is working fine.

Please can anyone tell me what is wrong ?
___________________________
This message was ported from CCS's old forum
Original Post ID: 5956
R.J.Hamlett
Guest







Re: float in a structure problem
PostPosted: Wed Jul 31, 2002 8:39 am     Reply with quote

:=Dear,
:=
:=PCWH v3.103 and PIC18F452
:=
:=I have this structure:
:=
:=struct
:= {
:= char text_eng [DIM1];
:= float value_min;
:= float value_max;
:= float value_default;
:= float value;
:= char value_unit [DIM3];
:= } menu [DIM2];
:=
:=
:=main
:={
:=int8 menu_cnt = 0;
:=
:=menu[menu_cnt].value = 12.34567;
:=menu[menu_cnt].value += 0.05;
:=}
:=
:=(the code is only to describe the problem, not running)
:=
:=the allocation of 12.34567 is working, but after the addition of 0.05 the value in menu[menu_cnt].value has not changed, it
:=is still 12.34567
:=
:=Instead of menu[menu_cnt].value I have tried a float variable that is not defined in the structure and it is working fine.
:=
:=Please can anyone tell me what is wrong ?
The compiler...
Try again, with a single structure (as opposed to an array). For me at least, it is arrays of structures that are causing problems, as opposed to single structures. I do an operation, where a block of data inside a structure is sent over SPI, and taking the address of the element, when using an array of structures, gives an address that is outside the area defined for the structure array. This works OK, in 3.100.

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 5959
nilsener
Guest







Re: float in a structure problem
PostPosted: Wed Jul 31, 2002 9:30 am     Reply with quote

:=:=Dear,
:=:=
:=:=PCWH v3.103 and PIC18F452
:=:=
:=:=I have this structure:
:=:=
:=:=struct
:=:= {
:=:= char text_eng [DIM1];
:=:= float value_min;
:=:= float value_max;
:=:= float value_default;
:=:= float value;
:=:= char value_unit [DIM3];
:=:= } menu [DIM2];
:=:=
:=:=
:=:=main
:=:={
:=:=int8 menu_cnt = 0;
:=:=
:=:=menu[menu_cnt].value = 12.34567;
:=:=menu[menu_cnt].value += 0.05;
:=:=}
:=:=
:=:=(the code is only to describe the problem, not running)
:=:=
:=:=the allocation of 12.34567 is working, but after the addition of 0.05 the value in menu[menu_cnt].value has not changed, it
:=:=is still 12.34567
:=:=
:=:=Instead of menu[menu_cnt].value I have tried a float variable that is not defined in the structure and it is working fine.
:=:=
:=:=Please can anyone tell me what is wrong ?
:=The compiler...
:=Try again, with a single structure (as opposed to an array). For me at least, it is arrays of structures that are causing problems, as opposed to single structures. I do an operation, where a block of data inside a structure is sent over SPI, and taking the address of the element, when using an array of structures, gives an address that is outside the area defined for the structure array. This works OK, in 3.100.
:=
:=Best Wishes

Thanks, you are right, it is the compiler again ! I have tried something else like this:

menu[menu_cnt].value += 0.05; -- is not working
menu[0].value += 0.05; -- works fine but is unusable

I will post it to CCS that they can fix the bug in the next version.
___________________________
This message was ported from CCS's old forum
Original Post ID: 5963
R.J.Hamlett
Guest







Re: float in a structure problem
PostPosted: Wed Jul 31, 2002 9:44 am     Reply with quote

:=:=:=Dear,
:=:=:=
:=:=:=PCWH v3.103 and PIC18F452
:=:=:=
:=:=:=I have this structure:
:=:=:=
:=:=:=struct
:=:=:= {
:=:=:= char text_eng [DIM1];
:=:=:= float value_min;
:=:=:= float value_max;
:=:=:= float value_default;
:=:=:= float value;
:=:=:= char value_unit [DIM3];
:=:=:= } menu [DIM2];
:=:=:=
:=:=:=
:=:=:=main
:=:=:={
:=:=:=int8 menu_cnt = 0;
:=:=:=
:=:=:=menu[menu_cnt].value = 12.34567;
:=:=:=menu[menu_cnt].value += 0.05;
:=:=:=}
:=:=:=
:=:=:=(the code is only to describe the problem, not running)
:=:=:=
:=:=:=the allocation of 12.34567 is working, but after the addition of 0.05 the value in menu[menu_cnt].value has not changed, it
:=:=:=is still 12.34567
:=:=:=
:=:=:=Instead of menu[menu_cnt].value I have tried a float variable that is not defined in the structure and it is working fine.
:=:=:=
:=:=:=Please can anyone tell me what is wrong ?
:=:=The compiler...
:=:=Try again, with a single structure (as opposed to an array). For me at least, it is arrays of structures that are causing problems, as opposed to single structures. I do an operation, where a block of data inside a structure is sent over SPI, and taking the address of the element, when using an array of structures, gives an address that is outside the area defined for the structure array. This works OK, in 3.100.
:=:=
:=:=Best Wishes
:=
:=Thanks, you are right, it is the compiler again ! I have tried something else like this:
:=
:=menu[menu_cnt].value += 0.05; -- is not working
:=menu[0].value += 0.05; -- works fine but is unusable
:=
:=I will post it to CCS that they can fix the bug in the next version.
:=
The _really_ annoying thing for me, is that this bug existed back in the 3.0xx compilers. I complained to CCS, and they fixed it in 3.099 (also retained the fix in 3.100). Yet not even half a dozen versions latter, and they have re-introduced the problem. As you have found, it works for a 'fixed' index to the array, but not when a variable is used.
You can 'bodge' round it, by testing your variable, and selecting different 'fixed' index values according to the contents of menu_cnt. Hard work, but at least it makes it useable... :-(

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 5964
nilsener
Guest







Re: float in a structure problem
PostPosted: Thu Aug 01, 2002 4:32 am     Reply with quote

:=:=:=:=Dear,
:=:=:=:=
:=:=:=:=PCWH v3.103 and PIC18F452
:=:=:=:=
:=:=:=:=I have this structure:
:=:=:=:=
:=:=:=:=struct
:=:=:=:= {
:=:=:=:= char text_eng [DIM1];
:=:=:=:= float value_min;
:=:=:=:= float value_max;
:=:=:=:= float value_default;
:=:=:=:= float value;
:=:=:=:= char value_unit [DIM3];
:=:=:=:= } menu [DIM2];
:=:=:=:=
:=:=:=:=
:=:=:=:=main
:=:=:=:={
:=:=:=:=int8 menu_cnt = 0;
:=:=:=:=
:=:=:=:=menu[menu_cnt].value = 12.34567;
:=:=:=:=menu[menu_cnt].value += 0.05;
:=:=:=:=}
:=:=:=:=
:=:=:=:=(the code is only to describe the problem, not running)
:=:=:=:=
:=:=:=:=the allocation of 12.34567 is working, but after the addition of 0.05 the value in menu[menu_cnt].value has not changed, it
:=:=:=:=is still 12.34567
:=:=:=:=
:=:=:=:=Instead of menu[menu_cnt].value I have tried a float variable that is not defined in the structure and it is working fine.
:=:=:=:=
:=:=:=:=Please can anyone tell me what is wrong ?
:=:=:=The compiler...
:=:=:=Try again, with a single structure (as opposed to an array). For me at least, it is arrays of structures that are causing problems, as opposed to single structures. I do an operation, where a block of data inside a structure is sent over SPI, and taking the address of the element, when using an array of structures, gives an address that is outside the area defined for the structure array. This works OK, in 3.100.
:=:=:=
:=:=:=Best Wishes
:=:=
:=:=Thanks, you are right, it is the compiler again ! I have tried something else like this:
:=:=
:=:=menu[menu_cnt].value += 0.05; -- is not working
:=:=menu[0].value += 0.05; -- works fine but is unusable
:=:=
:=:=I will post it to CCS that they can fix the bug in the next version.
:=:=
:=The _really_ annoying thing for me, is that this bug existed back in the 3.0xx compilers. I complained to CCS, and they fixed it in 3.099 (also retained the fix in 3.100). Yet not even half a dozen versions latter, and they have re-introduced the problem. As you have found, it works for a 'fixed' index to the array, but not when a variable is used.
:=You can 'bodge' round it, by testing your variable, and selecting different 'fixed' index values according to the contents of menu_cnt. Hard work, but at least it makes it useable... :-(
:=
:=Best Wishes

Thanks, it works Smile
I made some more experiences and found a workround for big arrays.

main()
{
float f;

f = menu[menu_cnt].value;
f += 0.05;
menu[menu_cnt].value = f;
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 5998
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