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

Vinzent Höfler JeLlyFish.software at gmx.net
Wed Aug 13 20:23:40 CEST 2008


Vincent Snijders wrote:
> Vinzent Höfler schreef:
>> Joost van der Sluis wrote:
>>
>>> Ok, so I misunderstood you. You want that the compiler complains if you
>>> don't assign the result of a function. While that can be done, I don't
>>> think you want that.
>>
>> Well, don't decide for others, please. I am a stupid programmmer, I am 
>> making mistakes all the time, and any feature that could possibly stop 
>> me from making such is - in my opinion - a useful feature.
> 
> Yes, but this feature doesn't because it gives so many false positives 
> that I end up ignoring such warnings completely.

IBTD. I actually *used* that feature, until it became unusable due to 
the inability to compile constructors at all. So don't get me wrong, but 
maybe I am in a better position to judge its usefulness. Especially 
because it doesn't generate warnings, it simply refuses to compile. So 
you can't even choose to ignore it.

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.

Well, I even think that pointing the maintenance programmer to the fact 
that I deliberately chose to ignore the return value instead of possibly 
  having forgotten it, might help understanding the code better.

At last, there's a pretty good reason why in some (C-)coding standards 
it is even mandatory to cast unused function results to (void). Although 
I'd sure find it a bit annoying to write "(void) printf ("Foo");". But 
contrary to Pascal procedures, C only knows functions and almost any of 
it returns something that's non-void, useful or not. ;)


Vinzent.



More information about the fpc-pascal mailing list