One portable way, BTW, is to use a local dummy variable and assign to it (in case of strings, e.g., you might want to assign its `Length' to a dummy integer, to avoid a possible string copy). This makes the parameter to be used, and a good optimizer should eliminate the dummy variable and the assignment.
Agreed, although that is fairly ugly and requires defining a temporary variable (or for different types a temporary for each type).
Another (non-portable) option, would be if we had the way of explicitly specifying "throw away the result" akin to C's (void) (which sadly is needed more and more for compatibility with the idiotic C calls that pointlessly return their parameter), then that could be used to accomplish this without a dummy variable, but would not solve the problem of source code compatibility, although it would change the location of the GPC macro and make it somewhat clearer and more consistent in location.
For example, if GPC supported a syntax like:
nil := whatever
Then that could be used to both throw away function results (but clearly mark them in the code which is exactly as safe as writing dummy_result := whatever) as well as provide a mechanism for "using" unused variables.
Unfortunately, while I could probably define a macro like:
{$ifdef __GPC__} {$definec NOTUSED attribute(unused)} {$elsec} {$definec NOTUSED } {$endc}
and add the NOTUSED entries to my parameters, I cannot think of any way to get GPC to ignore or udnerstand the {$unused( param_name )}
Could $unused either be supported to disable the warning for a variable/parameter, or could we get some sort of flag to allow {$unused(x,y,z)} to be silently ignored so that it is possible to write code that is source compatible?
I don't really like this syntax, because (our) compiler directives usually don't refer directly to language elements (identifiers).
So I'd rather tend to ignore it -- perhaps ignore `{$unused...}' in Mac mode with a warning otherwise (or only if `-pedantic'?), just like we ignore several BP directives?
Ignoring it would be fine, preferably not only in Mac mode, it would need its own switch or pedantic would be fine by me (I don't generally use Mac mode as such even though it is Mac specific because I want to access the general GPC facilities in as GPC a manner as possible). Ignoring {$unused} should be safe for anything other than pedantic mode since other than leading to a possible source compatibility issue, it can't do any real damage since it only hides a warning and if it is ignored by GPC it will just mean the warning is displayed again...
All that said, if it was possible to support it in GPC, even though it referred to a language element from a Macro, it would be preferable since the syntax is relatively clean and fairly clear as to what it is doing and would mean less hacks in my MW/GPC source compatibility.
But as usual, any solution you're willing to go with is a better solution that not being able to write source compatible code.
Thanks, Peter.