Adriaan van Os wrote:
Scott Moore wrote:
IP Pascal uses:
procedure dummy(x, y: integer);
var a: integer;
begin
reference(x); reference(y)
end;
Which is straightforward. Reference is a built-in that sets the variable as referenced.
Sorry, but I fiind it absurd to write actual code to get rid of an unwanted warning (even if the actual code translates into dummy code). Why do we want warnings anyway ? Well, if there are many warnings on every build or compile, that only irritates the programmer and the warnings will miss their purpose. So, the idea is to have software that eventually compiles without warnings.
Exactly.
There are two valid ways to get rid of warnings. The programmer carefully inspects the program source that produces the warning and then decides:
(1) the compiler is right, the source is dangerous and should be changed, òr (2) the compiler warning is irrelevant (or wrong) in the specific context of a portion of the source code, the compiler should stop complaining there.
In the second case, we need fine control over warnings, that is, a compiler directive to put specific warnings off locally with {$local W no-xxx} ... {$endlocal} or whatever.
That's one way, but it's debatable whether it's the best way.
Some year ago, people (including myself) used to use `{$W-} ... {$W+}' around such code portions, in the absence of many finer-grained warning options (as well as `{$local}', but that's a side-issue here). Obviously, this lead to some justified warnings ignored occasionally.
Now, a local "no-unused-warnings" options would be finer-grained than `W-', but still not as much as possible. For one thing, it concerns all parameters. One can imagine a fixed parameter form where some parameters are always needed, and some are "optional", so you do want warnings if you don't used the required parameters.
Another thing, you'd have to enclose the whole routine (not just the header) with this option since the fact that parameters are unused turns out at the end of the routine (unless you put the directive around the final `end;' or such which also obscures the matter). But then it affects also subroutines which generally don't have the same fixed parameter form, so you want warnings there.
Now, to the case of unused parameters - they don't hurt, unused parameters won't crash software.
Crashing is not the only kind of bug.
But - apparently we missed an opportunity to eliminate the unused parameter to make the software faster (at least in theory). However, this leads to problems when the parameter list of a procedure or function can not be changed, as is the case with e.g. callback routines. For those routines, we can should be able to put the check off with {$local W no-unused-parameter} ... {$endlocal}.
That's all - sorry, I don't see why need need control over individual parameters.
I'd prefer to. In addition, since I sometimes want to discard other values (function results), it might be preferable to do both things with a common syntax.
By the way, If the compiler were to eliminate unused parameters automatically, callback routines (and other fixed parameter list routines) will need local compiler directives anyway.
I don't think this will ever happen, except for inlined routines where the problem doesn't arise.
Frank