[splint-discuss] Printf formating and splint

J Schonberg schonm at yahoo.com
Sun Nov 28 01:54:03 EST 2004


Hello,

I don't understand why splint is having difficulty with the following
code.  The tools suggests that I can use the +relaxtypes.flag to
avoid the warning.  But I'm not sure this is really the correct
solution.

[~/C]$ more float.c
#include <stdio.h>

int main()
{
        int num;
        float denom;
        num = 1;
        denom = 4.0;
        printf ("%f\n",num / denom);
        return 0;
}
[~/C]$ splint float.c
Splint 3.1.1.2 --- 21 Oct 2004

float.c: (in function main)
float.c:9:17: Format argument 1 to printf (%f) expects double gets
int:
                 num / denom
  To allow all numeric types to match, use +relaxtypes.
   float.c:9:12: Corresponding format code

Finished checking --- 1 code warning

Why does the compiler see int here?  The expression is clearly
floating point.

[~/C]$ gcc -Wall -W -O2 -o run float.c
[~/C]$ ./run
0.250000

I'm using gcc 3.4.1.

Your suggestions would be welcome.

Thanks.



		
__________________________________ 
Do you Yahoo!? 
All your favorites on one personal page – Try My Yahoo!
http://my.yahoo.com 



More information about the splint-discuss mailing list