[fpc-pascal] why fpc do not use a known return function value
Mark Morgan Lloyd
markMLl.fpc-pascal at telemetry.co.uk
Tue Feb 3 10:23:18 CET 2015
misu kun wrote:
> Hi
> in this program test function has a known return value , and should be
> calculated in compile time , but fpc make it in real time !!!
> ---------------------
> program test;
> var c : int32;
> function test( p: int32): int32; inline;
> var i : int32;
> begin
> i := p;
> test := i+2+c+2+c+2+c;
> end;
> begin
> c:= test(128);
> end.
The initial value of c is undefined. How do you expect the compiler to
optimise it?
In the more general case, my recollection is that C has simpler scoping
rules, so there may be cases where it can optimise where a Pascal
compiler would be more cautious.
--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk
[Opinions above are the author's, not those of his employers or colleagues]
More information about the fpc-pascal
mailing list