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

Joost van der Sluis joost at cnoc.nl
Wed Aug 13 10:46:50 CEST 2008


Op woensdag 13-08-2008 om 01:27 uur [tijdzone -0700], schreef leledumbo:
> 
> Sometimes we forgot whether a function argument is passed by reference
> or by
> value. What if the result is actually important? For instance,
> consider the
> following (WARNING: True story): 

That's not so strange story. I think this is one of the (if not the)
most common mistakes of beginning programmers. And -as always- sometimes
the most experienced also make this mistake.

And there's no way the compiler can detect this. Because this could be
intentional. If you'll give a warning on such a construct, I think about
50% of the procedures would gresult in such a warning...

And the rules are simple: (for the beginners)

procedure Align(Addr: Pointer; Alignment: PtrUInt);
-> This procedure can't change any of it's parameters

procedure Align(const Addr: Pointer; Alignment: PtrUInt);
-> This procedure can't change any of it's parameters, and Addr can't be
changed inside the procedure also.

procedure Align(var Addr: Pointer; Alignment: PtrUInt);
-> This procedure can change Addr

If you really need those warnings, you could learn yourself to always
use 'const', 'var' or 'out'. And never without any of these words.

Joost






More information about the fpc-pascal mailing list