turbo-C and lint ?

D'Arcy J.M. Cain darcy at druid.uucp
Mon Mar 26 14:13:48 AEST 1990


In article <1966 at bruce.OZ> alanf at bruce.OZ (Alan Grant Finlay) writes:
> [...]
>check(x,y)
>long x;
>char *y;
>{
>printf("%10.10s ",y);
>}
>main()
>{
>check(10l,"testing");
>}
>
>If you now remove the l after the 10 in the procedure call the compiler
>issues no relevant warnings and the program misbehaves.  Can Turbo-C 
>generate a warning for this kind of error?

Yes if you code it properly (the ANSI way) as follows:

void check(long x,char *y)
{
printf("%10.10s ",y);
}
main()
{
check(10l,"testing");
}

The 'l' is now no longer necessary.  You won't get a warning message
because it will behave correctly.  The compiler knows when calling
"check" that the first argument is a long and does the promotion.  As
K&R2 says (pp 202):
	"If the function declaration in scope for a call is new-style, then
	the arguments are converted, as if by asignment, to the types of
	the corresponding parameters of the function's prototype."

Of course if the type can't be converted this fails but a suitable
error message will be generated.  This will catch the following error:
	check("testing", 10);

-- 
D'Arcy J.M. Cain (darcy at druid)     |   Thank goodness we don't get all 
D'Arcy Cain Consulting             |   the government we pay for.
West Hill, Ontario, Canada         |
(416) 281-6094                     |



More information about the Comp.lang.c mailing list