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

Vinzent Höfler JeLlyFish.software at gmx.net
Wed Aug 13 12:36:46 CEST 2008

leledumbo wrote:
> Joost van der Sluis wrote:
>> And there's no way the compiler can detect this.
> I don't think so. The compiler understand that a procedure doesn't return a
> value while a function does (i.e. trying to return a value from a procedure
> causes compile error). I haven't checked how compiler formats each
> function/procedure in the PPU but I think there should be an information
> whether it's a function or procedure. So, I think it's possible to detect if
> a function call is assigned to a variable or not.

Yes. Turn Extended Syntax off {$X-}, then a function result must be 
assigned to a variable. At least it used to be that way.

I was used to it, and in the case I really needed to ignore the result 
(and rather just wanted the side-effects of the function) I wrote things 

|if (IOResult <> 0) then {null};

Well, then ... I started with classes:

Now, constructors seem to actually return something (not surprisingly), 
so "inherited Create" did not compile anymore (and I remember that any 
attempt to assign this "result" to a dummy variable even failed). So, at 
that time I turned the extended syntax stuff back on.

So, in theory your problem is already solved in the compiler (even TP6 
already had it), but alas, in practice it's not really usable.


More information about the fpc-pascal mailing list