Sign in Join

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

Mailing lists / fpc-devel / 2005-10

Strange behaviour of ;

7 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

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

Alexander Todorov

Hi all,
i have noticed something strange and I am not sure if this is a bug or a feature.
------------------------
strSQL := Copy(strSQL,1,Length(strSQL)-1) + ' WHERE '; strSQL := strSQL ; + ConstructWhereClause;
--------------------------^

This part of code must construct a sql sttement which is used later on. the function ConstructWhereClause constructs everything that is behind `WHERE`. How ever having a semi-colon not in right place messed things up. The result is the old value of strSQL without the result of ConstructWhereClause.
Removing ; before the plus (+) character fixes the problem.

In Delphi this would cause a compilation error, but in FPC it does not. Why ?

Btw : the miss placed ; appeared because Lazarus' identifier completion adds a ; when the completion is selected. Any comments on this ?

Reply by email

Marc Weustink
to Alexander Todorov

I can confirm this on linux-i386 2.0.0 and darwin-ppc 2.0.1

It looks like "+ <some call>" is parsed wrong. The next "program" compiles fine.

Marc

program testplus;
{$mode objfpc} {$H+}
begin
   + ParamStr(0);
   + ParamCount;
   + Exit;
   + WriteLN;
end.
Alexander Todorov wrote 24 lines
Hi all, i have noticed something strange and I am not sure if this is a bug or a feature. ------------------------ strSQL := Copy(strSQL,1,Length(strSQL)-1) + ' WHERE '; strSQL := strSQL ; + ConstructWhereClause; --------------------------^ This part of code must construct a sql sttement which is used later on. the function ConstructWhereClause constructs everything that is behind `WHERE`. How ever having a semi-colon not in right place messed things up. The result is the old value of strSQL without the result of ConstructWhereClause. Removing ; before the plus (+) character fixes the problem. In Delphi this would cause a compilation error, but in FPC it does not. Why ? Btw : the miss placed ; appeared because Lazarus' identifier completion adds a ; when the completion is selected. Any comments on this ? _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Florian Klaempfl
to Marc Weustink
Marc Weustink wrote
I can confirm this on linux-i386 2.0.0 and darwin-ppc 2.0.1 It looks like "+ <some call>" is parsed wrong. The next "program" compiles fine.

Well, the compiler/parser thinks you use the unary + operator which it can safely throw away :) IIRC TP accepted the unary + operator for any expression so we did.

Show quoted text 48 lines
Marc program testplus; {$mode objfpc} {$H+} begin + ParamStr(0); + ParamCount; + Exit; + WriteLN; end. Alexander Todorov wrote: > Hi all, > i have noticed something strange and I am not sure if this is a bug or > a feature. > ------------------------ > strSQL := Copy(strSQL,1,Length(strSQL)-1) + ' WHERE '; > strSQL := strSQL ; + ConstructWhereClause; > --------------------------^ > > This part of code must construct a sql sttement which is used later on. > the function ConstructWhereClause constructs everything that is behind > `WHERE`. > How ever having a semi-colon not in right place messed things up. > The result is the old value of strSQL without the result of > ConstructWhereClause. > Removing ; before the plus (+) character fixes the problem. > > In Delphi this would cause a compilation error, but in FPC it does > not. Why ? > > Btw : the miss placed ; appeared because Lazarus' identifier > completion adds a ; when the completion is selected. Any comments on > this ? > _______________________________________________ > fpc-devel maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-devel > _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Peter Vreman
to Florian Klaempfl
Show quoted text 11 lines
Marc Weustink wrote: > I can confirm this on linux-i386 2.0.0 and darwin-ppc 2.0.1 > > It looks like "+ <some call>" is parsed wrong. The next "program" > compiles fine. Well, the compiler/parser thinks you use the unary + operator which it can safely throw away :) IIRC TP accepted the unary + operator for any expression so we did.

Delphi doesn't allow it. a single '+ <x>' is not changed implicitly to '0
+ <x>' so that there is checking done instead of ignoring the the '+'.

Reply by email

Tomas Hajny
to Peter Vreman

Date sent: Fri, 21 Oct 2005 09:46:05 +0200 (CEST) Subject: Re: [fpc-devel] Strange behaviour of ; From: "Peter Vreman"
To: "FPC developers' list"
Send reply to: FPC developers' list

Show quoted text 11 lines
> Marc Weustink wrote: >> It looks like "+ <some call>" is parsed wrong. The next "program" >> compiles fine. > > Well, the compiler/parser thinks you use the unary + operator which > it can safely throw away :) IIRC TP accepted the unary + operator > for any expression so we did. Delphi doesn't allow it. a single '+ <x>' is not changed implicitly to '0 + <x>' so that there is checking done instead of ignoring the the '+'.

TP/BP doesn't allow it either:

Turbo Pascal Version 7.0 Copyright (c) 1983,92 Borland International
T.PAS(3): Error 113: Error in statement.

  + ParamStr(0);
  ^

Tomas

Reply by email

Florian Klaempfl
to Tomas Hajny
Tomas Hajny wrote 28 lines
Date sent: Fri, 21 Oct 2005 09:46:05 +0200 (CEST) Subject: Re: [fpc-devel] Strange behaviour of ; From: "Peter Vreman" To: "FPC developers' list" Send reply to: FPC developers' list >>Marc Weustink wrote: >> >>>It looks like "+ <some call>" is parsed wrong. The next "program" >>>compiles fine. >> >>Well, the compiler/parser thinks you use the unary + operator which >>it can safely throw away :) IIRC TP accepted the unary + operator >>for any expression so we did. > >Delphi doesn't allow it. a single '+ <x>' is not changed implicitly to >'0 + <x>' so that there is checking done instead of ignoring the the >'+'. TP/BP doesn't allow it either: Turbo Pascal Version 7.0 Copyright (c) 1983,92 Borland International T.PAS(3): Error 113: Error in statement. + ParamStr(0);

But it allows
s:=+ParamStr(0);
iirc

Show quoted text 7 lines
^ Tomas _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Tomas Hajny
to Florian Klaempfl

Date sent: Sat, 22 Oct 2005 09:14:53 +0200
From: Florian Klaempfl
To: ,
FPC developers' list
Subject: Re: [fpc-devel] Strange behaviour of ;

Show quoted text 25 lines
Tomas Hajny wrote: >>>Marc Weustink wrote: >>> >>>>It looks like "+ <some call>" is parsed wrong. The next "program" >>>>compiles fine. >>> >>>Well, the compiler/parser thinks you use the unary + operator which >>>it can safely throw away :) IIRC TP accepted the unary + operator >>>for any expression so we did. >> >>Delphi doesn't allow it. a single '+ <x>' is not changed implicitly >>to '0 + <x>' so that there is checking done instead of ignoring the >>the '+'. > > > TP/BP doesn't allow it either: > > Turbo Pascal Version 7.0 Copyright (c) 1983,92 Borland > International > T.PAS(3): Error 113: Error in statement. > + ParamStr(0); But it allows s:=+ParamStr(0); iirc

True. However, I think this is different from what Marc was complaining about. Although I don't know the parser well, I believe the compiler should be able to differentiate between these two examples (unary +/- operator on the right side of an assignment, which is OK, from unary +/- operator on the left side or before a call, where there's probably no reason to accept it, because it certainly looks like a programmer's error).

Tomas

Reply by email