gcc int to float conversion problem
Ian Lance Taylor
iant@google.com
Fri Oct 6 01:49:00 GMT 2006
"Jason Lutz" <jlutz7777@hotmail.com> writes:
> int i_var1=1;
> float f_var2=0.0;
> char c_var3[10];
> f_var2=(float)i_var1/310.00;
> sprintf( c_var3, "%f", f_var2 );
>
> I then later print c_var3 to a web page I am hosting from my ARM
> processor. The important thing to note is that when it is printed, it
> only gives me ",,". If I just print an integer, it works fine. For
> example:
>
> int i_var1=5;
> char c_var3[10];
> sprintf( c_var3, "%i", i_var1 );
>
> Is there an error with the gcc compiler for ARM (arm-elf-gcc)? Maybe
> I am doing something wrong and just cannot figure it out, but if I use
> this code on my x86 and do a printf, it works fine with the integer or
> float. Any workaround would be much appreciated.
This looks like a problem with whatever C library you are using, not
with gcc itself. gcc does not provide sprintf.
It is possible that there could be a compiler problem here related to
passing float to a varargs function, but I don't see how that could
wind up producing ",," no matter how much it messed up.
It is of course also possible that c_var3 is getting clobbered
somewhere before you print it.
Ian
More information about the Gcc-help
mailing list