1

i am programming ATmega128 using avr studio 4. When I display floating point values, I get warning message which says

Lines causing warning message to appear are as follows :

float temperature;
//{other parts}
fprintf(stderr,"Temp: %0.2f ", temperature);

warning message is:

../main.c:128:2: warning: format '%f' expects argument of type 'double', but argument 4 has type 'float' [-Wformat]"

When displaying it in double, I see other random values..How can I get rid of this warning message ?

sujan_014
  • 516
  • 2
  • 8
  • 22
  • Please post some code or at least the line thats causing the error (../main.c:128:2) and maybe the output value(s) you get and you expect. – Rev May 23 '14 at 09:54
  • Is this of any help? http://stackoverflow.com/questions/6395726/how-does-printf-and-co-differentiate-beetween-float-and-double -- I'd suggest explicitly casting to double (wich is the same as float in avr-gcc) and see if that makes a difference. – JimmyB May 23 '14 at 11:23
  • @Rev1.0 - I have pasted lines from my code. Output reading from the temperature sensor is as expected when using above shown declaration but I get warning message expecting double value. I wanted to get rid of this. – sujan_014 May 26 '14 at 01:44
  • @Hanno Binder - I went through link provided by you. What I understood is that when using printf, float argument is converted to double. Since I did not have to deal with double before I did not care about it. But I have one simple question. In avr-gcc can I use double instead of float if size does not matter. and does avr-gcc treat float and double in same way ? – sujan_014 May 26 '14 at 01:53
  • Well, `temperature` should be implicitly promoted to `double` in any case. What exactly do you mean with "When displaying it in double, I see other random values". You mean when you explicitly cast to `double` the displaed value is wrong? I don't see why that should happen. – Rev May 26 '14 at 07:12
  • Regarding float and double in avrgcc: Both are implemented with 4-Byte length and have exactly the same internal format. However, they are still different types. – Rev May 26 '14 at 07:16
  • Btw, "using avr studio 4". Why do you do that?! :) I read in Rev1.0's answer that it's been fixed in gcc 4.1! - We're at 4.8.x now. Consider upgrading! – JimmyB May 26 '14 at 15:03

1 Answers1

1

I did some further digging and the warning is/was actually a bug with AVRGCC. It was marked as resolved in GCC v4.1.0 but judging the comments it wasn't properly fixed. There was another fix on Aug 26 16:52:19 2013 UTC which probably fixed the issue as desired.

It seems the float to double promotion wasn't working properly because the GCC code assumed two different sizes for both types.

Rev
  • 5,827
  • 4
  • 27
  • 51