Adriaan van Os wrote:
Frank Heckenbach wrote:
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.
It depends on the implementation, it could be as fine-grained as we want it to be. So, if we need control over individual parameters, local warning directives could be put in the header around individual 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).
That would indeed obscure the matter. What I like about Pascal is writing software that achieves the highest possible degree of transparency and translucency. A Pascal algorithm shouldn't be a bunch of tricks but an elegant expression of clear logical ideas. So, in this case, if we want the advantages of unused-parameter checking, we need a way to say "hey, this is a routine with unused parameters" or "hey, this parameter is unused". That information belongs in the header, not in the body. Next, it is a matter of compiler implementation to use that information to do the actual unused-parameter check in the body (or not). The compiler could/should remember all information specified in the header, including compiler directives.
It seems you misunderstand what compiler directives are or how they work. Compiler directives (as in GPC, and AFAIK also BP, Delphi and other compilers) switch certain compiler settings *while* the source is being processed.
The `-Wunused...' options mean (by definition) "warn about all undefined ...'s". Making it a compiler directive would then mean "warn about all undefined ...'s while the directive is turned on".
You may wish that it would mean "warn about all undefined ...'s that were declared while the directive was turned on", but that's not the way it works.
What's more like what you have in mind might be attributes on the parameters, as e.g. the GNU C compiler allows for. I've also thought about them in this context, and probably we could implement them. The disadvantages I see are (a) it adds another bit of extra nonstandard syntax (even if the attribute syntax is already there in GPC, adding another place where it's allowed means new syntax), (b) it doesn't care take of discarding function results, so we'd still want to add another thing. (I'd rather add one general thing than several more specific things, and again, adding a built-in "procedure", even with nonstandard semantics, is a less severe change than adding new syntax.)
In addition, since I sometimes want to discard other values (function results), it might be preferable to do both things with a common syntax.
Discarding a mechanical result value, actually returned by a function, is something completely different from the logical specification of an unused parameter. Nothing is discarded in the latter case.
Sure, something is discarded! The caller passes some value (or reference) in the parameter, and the called routine discards this value.
Frank