[fpc-pascal]possible bug in fpc-1.00 (yes, not the newest version)

Michael.VanCanneyt at Wisa.be Michael.VanCanneyt at Wisa.be
Sat Dec 23 11:05:52 CET 2000


On Sat, 23 Dec 2000, Tjabo Kloppenburg wrote:

> hi,
> 
> I'm using fpc on a linux box (i386). fpc version is
> "Free Pascal Compiler version 1.00 [2000/07/11] for i386".
> 
> ok, I want to have a simple tool exiting with return code 0 or 1 if a 
> substring is in another string or not.
> 
> this is the source code:
> 
> begin
>   if paramcount = 2 then begin
>     writeln( pos(paramstr(1), paramstr(0)) );
>     writeln( pos(paramstr(0), paramstr(1)) );
>   end;
> end.

ParamStr is 1 based, not zero based. So your code should read
 begin
   if paramcount = 2 then begin
     writeln( pos(paramstr(2), paramstr(1)) );
     writeln( pos(paramstr(1), paramstr(2)) );
   end;
 end.

> 
> now, when compiling "ppc substr.pas", and starting:
> substr IsThisABug u
> 
> it writes:
> 0
> 0
> 
> Am I wrong in thinking that at least one line should have been "-1"?

Yes. -1 is simply not a possible value. Pos returns 0 if the substring isn't
found, or the actual position, which is also 1 based.

Michael.





More information about the fpc-pascal mailing list