Path: utzoo!attcan!telly!druid!darcy From: darcy@druid.uucp (D'Arcy J.M. Cain) Newsgroups: comp.lang.c Subject: Re: turbo-C and lint ? Keywords: PD lint Message-ID: <1990Mar26.041348.1413@druid.uucp> Date: 26 Mar 90 04:13:48 GMT References: <1964@bruce.OZ> <1990Mar20.130947.16583@cs.eur.nl> <1966@bruce.OZ> Reply-To: darcy@druid.UUCP (D'Arcy J.M. Cain) Organization: D'Arcy Cain Consulting, West Hill, Ontario Lines: 45 In article <1966@bruce.OZ> alanf@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@druid) | Thank goodness we don't get all D'Arcy Cain Consulting | the government we pay for. West Hill, Ontario, Canada | (416) 281-6094 |