[fpc-pascal] weird compiler(?) problem
Sven Barth
pascaldragon at googlemail.com
Thu Feb 13 16:53:08 CET 2014
Am 13.02.2014 16:42, schrieb Xiangrong Fang:
> Hi All,
>
> I encountered a very strange problem. The code looks like this:
>
> //In Unit1.pas:
>
> //sel is an object of TIntVector and
> //TIntVector = specialize TVector<Integer>
> *sel.Sort([soEliminateNA, soReversed]);
> *
>
> //In vector.pas:
>
> procedure TVector.Sort(Options: SortOptions);
> var
> i, gap, order, first, last, pos: Integer;
> Temp: T;
> begin
> *if FCount < 2 then**Exit; <-- problem here*
> if soReversed in Options then order := 1 else order := -1;
> ... ...
>
> My purpose is to skip sorting if the vector's element count is less
> than 2.
>
> Now the problem is that this statement does not have any effect (see
> attached screenshot). The debugger refuse to stop on the breakpoint,
> but goes directly to the line below it!
>
> What's more strange is that if I change the line to break after
> “then”, i.e.:
>
> begin
> *if FCount < 2 then***
> *Exit;*
> if soReversed in Options then order := 1 else order := -1;
> ... ...
>
> Now it worked!
>
> I also wrote a simple test program, but can NOT reproduce this bug there.
>
> My TVector source code is here:
> https://github.com/xrfang/fpcollection/blob/master/src/units/vector.pas
>
>
> Any help is greatly appreciated.
Could you please check/compare the generated assembler code? Use "-al"
to have the compiler generate it and you'll need to look at the file
where you specialized the TVector.
Regards,
Sven
More information about the fpc-pascal
mailing list