[fpc-pascal] Compiler option to check return value ignorance

"Vinzent Höfler" JeLlyFish.software at gmx.net
Wed Aug 13 22:23:43 CEST 2008


-------- Original-Nachricht --------
> Datum: Wed, 13 Aug 2008 16:02:10 -0400
> Von: Jeff Wormsley <daworm10 at comcast.net>
> An: FPC-Pascal users discussions <fpc-pascal at lists.freepascal.org>
> Betreff: Re: [fpc-pascal] Compiler option to check return value ignorance

> 
> 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?

Apart from the fact that I write

|if not SomeFunction <> Constant_Of_Sometype then {null};

yes. And it's a compile time error.

> 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.

I didn't ask for a change. The feature is already there.

All I would ask for that {$EXTENDED_SYNTAX OFF} wouldn't be equivalent to "I refuse to compile constructors" (and maybe in turn allow the use of "inherited Create" without this strict check).

Sure, I won't force anyone to use it. But I know environments where your employer would force you to. Even worse, there are environments where merely assigning the result to a dummy variable wouldn't be enough to satisfy the strict checks, you'd have to do something useful with it. And to be honest, there aren't many cases where you really can ignore the result of the function and keep the good conscience of having it done right. If a function in Pascal returns something it's usually useful.


Vinzent.

-- 
GMX startet ShortView.de. Hier findest Du Leute mit Deinen Interessen!
Jetzt dabei sein: http://www.shortview.de/wasistshortview.php?mc=sv_ext_mf@gmx



More information about the fpc-pascal mailing list