Billy Mays <> writes:
> Periodically I see code that looks similar to this:
>
> void do_something(int a, int b)
> {
> (void) b;
> printf("A is %d\n", a);
> }
>
> What does this typecast do? Running code like this through lint
> complains the "(void) b" statement does nothing. Any thoughts?
It's probably intended to silence a warning about b not being
used in the function. Whether it actually does so depends on the
compiler or other tool being used. Some compilers might issue a
warning if b isn't referred to at all, but shut up if it appears as
"(void) b;". For whatever version of lint you're using, as you've
seen, it doesn't work particularly well.
(Lints typically recognize directives in the form of C comments that
tell them to inhibit certain warnings. I say "lints" rather than
"lint" because there are multiple versions of lint, just as there
are multiple distinct C compilers.)
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"