more questions about efficient C code
Cesar Quiroz
quiroz at rochester.UUCP
Tue Jul 2 03:39:14 AEST 1985
>From article <3136 at drutx.UUCP> (version B 2.10.2 9/18/84; site rochester.UUCP version B 2.10.1 (Denver Mods 7/26/84) 6/24/83; site drutx.UUCP rochester!seismo!harvard!think!mit-eddie!genrad!decvax!harpo!whuxlm!whuxl!houxm!ihnp4!drutx!zarth zarth at drutx.UUCP (CovartDL)):
>I have noticed lately that if I have the following:
>
> foo()
> {
> char c;
>
> if((c = getchar()) != '\n') {
> /* more code here */
> }
> }
>
>and I do not use 'c' any where else lint complains. I get the message
>
> c set but no used in function foo
>
. . .
>
> - Zarth Arn
Seems like a very desirable behavior in the part of Lint. Either you really
need the value of c someplace else (and then your program contains a bug) or it
could be easily simplified as:
foo()
{
/* NOT NEEDED: char c; */
if(((char) getchar()) != '\n') {
/* more code here */
}
}
Or something similar that doesn't keep the value of getchar() in a useless
variable. At any rate, be sure you really don't need it!
Cesar
More information about the Comp.lang.c
mailing list