by throwaway125 · 12y ago · 0 comments
The language often (always?) has facilities to remove those warnings on a case by case basis. For example when you don't want to use a parameter you can actively let the compiler know without assigning the variable to itself: you can only include the type and not the name:
int fn(int, void*);
int fn(int num, void* /*extra*/) {
// If the name extra is commented out the compiler will
// not warn that you are not using it. Now it is very
// clear that not using this variable was an active choice
// and not a mistake.
return num;
}
edit: as pbsd pointed out commenting out extra is not portable C code, though I believe the wider point still stands. These warnings can be very useful and should be be reviewed before ignoring them. (void)extra;
to shut the compiler up.