[fpc-pascal] weird compiler(?) problem

Xiangrong Fang xrfang at gmail.com
Thu Feb 13 17:09:33 CET 2014


Hi Sven,

I don't know how to find that, could you please explain?  Attached
dbg.tar.bz2 is the demo program and assembly code generated by the compile.
Where is the "point of specialization" in that file?

My working program is quite complex, I copied part of the code related to
this problem in snippet.pas

Thank you!
Xiangrong


2014-02-13 23:53 GMT+08:00 Sven Barth <pascaldragon at googlemail.com>:

> 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
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20140214/705cfbfc/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dbg.tar.bz2
Type: application/x-bzip2
Size: 6852 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20140214/705cfbfc/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: snippet.pas
Type: text/x-pascal
Size: 1266 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20140214/705cfbfc/attachment.pas>


More information about the fpc-pascal mailing list