RE: floats?
I thouhgt so, but I wasn't sure, and you guys confirmed it!
As Vince said, this is how I was trying it:
f_ExtIn[0], f_ExtIn[1],f_ExtIn[2], f_ExtIn[3]
or
.... pointed to by f_ExtIn, f_ExtIn+1, f_ExtIn+2,f_ExtIn+3.
but the compiler's watch was showing something else. However I tried setting
variable watches in main instead of the function and it did work. Its
probably a bug in the compiler... its one of thoses special compilers that
allow you to write C code for microprocessors, they just released a new
version!
I can't thankyou guys enough, man, books don't always give the answer, I am
glad that for desperate times, I can come on the news groups for a tip or
two. :)
Thankyou all for your feedback, I really appreciate it....
I hope you all have a nice day, and hope to talk to you in future questions!
Sincere and best regards
Robert
"Robby" wrote:
Hello,
For the first time I find myself actually needing to manipulate floats as
opposed to just reading about them! And so, again, I am in need of basic C
advice, for my attempts of finding a solution have failed me !!!
Here's what I know, In C, floats are 32 bits right!
I am having difficulty assigning a float value to a float array?
I am declaring a global float array, and then I must pass it down a few
functions, so I supplied a simplified program doing just that.
Here is the code:
////////////////////////////////////////////////////////////////////////////
float f_ExtIn[4] = {2.1,4.2,6.3,8.4};
void IO_Interface( float f_ExtIn[]);
void IOSS ( float *f_ExtIn );
void CPUA_I2CTEMP (float *f_ExtIn);
void main()
{
IO_Interface( f_ExtIn );
}
void IO_Interface( float f_ExtIn[] )
{
IOSS( f_ExtIn );
}
void IOSS(float *f_ExtIn)
{
CPUA_I2CTEMP(f_ExtIn);
}
void CPUA_I2CTEMP(float *f_ExtIn)
{
float reading;
reading = read_full_temp(); //Returns room temperature as, ex:76784565
reading /= 100.0; //Moves over the decimal point to get
76.78 Deg F.
//reading, is now a float!
f_ExtIn[0] = reading; //Assign to float array. OKAY it works!
//*(f_ExtIn+4)= reading; //Attempting to write to the second element, but
//f_ExtIn[4] = reading; //these don't work!
}
/////////////////////////////////////////////////////////////////////////
In the code right above, I was able to store the reading in the first
location of the f_ExtIn array over writting the default value of 2.1. But say
I want to store the same reading in the second element of the float array?
I have tried many ways and I am getting many strange results.
I just want to be able to assign reading to any one of the four elements
of the f_ExtIn array?????
f_ExtIn[0] = reading; //This works as shown in code above.
//So why don't the others work???
f_ExtIn[1] = reading; //This doesn't work
f_ExtIn[4] = reading; //This doesn't work
f_ExtIn[8] = reading; //This doesn't work
OR
*(f_ExtIn+0) = reading; //This doesn't work either
But if I dereference say *(f_ExtIn+4) I get the original value store
innitially of
4.2 or actually 4.9999999... confused!!!!
Why do I see the innitial value but can't over write it with
*(f_ExtIn+4)= reading;
or
f_ExtIn[4] = reading;
My books don't show anything that can lead me to understand why this is
happening.
I would sincerely appreciate the help, at this point I don't know what else
to try.
I know this is basic C, however, I have spent 5 hours reviewing code samples
and I feel exausted!
The compiler I am using defines floats as being 32 bits long, so, I have
read that most compilers store floats by 4 bytes or even at 8 bytes... at
least I think?
I am so confused!!!
All help *very* appreciated!
Thankyou!
--
Best regards
Robert