Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2000-12

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

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Tjabo Kloppenburg

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.

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"?

Best regards,
Tjabo

Unknown author
to Tjabo Kloppenburg
Tjabo Kloppenburg wrote 16 lines
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.
Show quoted text 9 lines
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.

Cor Slot
to Unknown author

Hi Michael.VanCanneyt,

On Sat, 23 Dec 2000 11:05:52 +0100 (CET), wrote:

Michael.VanCanneyt> ParamStr is 1 based, not zero based. So your code should read

That is not totally true... ParamStr(0) does exist, it is the name of the executed program.

Cheers,
Cor.

==============================
Cor.J. Slot Rotterdam [NL]
Voice/FAXmail +31 20 877 86 64
==============================