Recent

Author Topic: In {$MODE TP} refuses to compile 1+PChar, but compiling PChar+1  (Read 3759 times)

Avinash

  • Full Member
  • ***
  • Posts: 126
Code: Pascal  [Select][+][-]
  1. {$MODE TP}
  2. var P: PChar;
  3. begin
  4.   P := 1 + P;
  5. end.

Error: Operation "+" not supported for types "ShortInt" and "PChar"

Code: Pascal  [Select][+][-]
  1. {$MODE TP}
  2. var P: PChar;
  3. begin
  4.   P := P + 1;
  5. end.

OK

AlexTP

  • Hero Member
  • *****
  • Posts: 2715
    • UVviewsoft
Re: In {$MODE TP} refuses to compile 1+PChar, but compiling PChar+1
« Reply #1 on: July 01, 2021, 07:09:55 pm »
Order of operands matters.

Avinash

  • Full Member
  • ***
  • Posts: 126
Re: In {$MODE TP} refuses to compile 1+PChar, but compiling PChar+1
« Reply #2 on: July 01, 2021, 07:53:01 pm »
Very well noticed. But I meant that since the order does not matter for MODE FPC, OBJFPC and Turbo Pascal compiler itself (with that the {$MODE TP} mode should be compatible), most likely something wrong here.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12905
  • FPC developer.
Re: In {$MODE TP} refuses to compile 1+PChar, but compiling PChar+1
« Reply #3 on: July 01, 2021, 09:43:19 pm »
Is this syntax supported by TP?

Avinash

  • Full Member
  • ***
  • Posts: 126
Re: In {$MODE TP} refuses to compile 1+PChar, but compiling PChar+1
« Reply #4 on: July 01, 2021, 10:27:49 pm »
With the "Extended syntax" {$X+} (is on by default) TPC compiles both cases, with {$X-} none.

Just like FPC does (Free Pascal Programmer’s Guide):
Quote
1.3.40 $X or $EXTENDEDSYNTAX : Extended syntax
Extended syntax allows you to drop the result of a function and perform pointer arithmetic. This means that you can use a function call as if it were a procedure. By default this feature is on.

 

TinyPortal © 2005-2018