[fpc-pascal] Compiler option to check return value ignorance
Jeff Wormsley
daworm10 at comcast.net
Wed Aug 13 22:02:10 CEST 2008
Vinzent Höfler wrote:
> I just grep'ped the actual sources of the project (about 70K LOC) and
> I found exactly four occurences of my "if Ignore_Result() then
> {null};" pattern with FPC runtime routines. There are others, but
> those routines access hardware and on some occasions I really need to
> ignore failures there.
>
> 2x IOResult
> 1x SysUtils.DeleteFile
> 1x BaseUnix.fpChMod
>
> Twice more of this pattern occured to avoid the compiler hint of
> unused parameters. So if "false positives" is an indicator for
> uselessness of a compiler message, I'd tend to doubt the usefulness of
> that.
So, if I read you correctly, if you call a function that you don't care
what the result is, instead of:
Begin
SomeFunction(123); // Ignore result
End;
... you would have us write:
Var Dummy: SomeType;
Begin
Dummy := SomeFunction(123);
End;
... or else get warnings from the compiler?
I'm afraid there are tons of code out there that this would effect. I
don't think any of the maintainers of such code would appreciate that
change much. Maybe, just maybe, an optional {$MODE
ULTRA_STRICT_FUNCTION_RESULT_USE} type compiler option, whose default
was off, would be ok, but otherwise such a change would be far worse
than the "problem" you are trying to address (someone improperly not
using the function result when they were supposed to).
Jeff.
--
I haven't smoked for 1 year, 11 months and 3 weeks, saving $3,274.62 and
not smoking 21,830.81 cigarettes.
More information about the fpc-pascal
mailing list