Recent

Author Topic: [SOLVED] Default behavior of C like operators  (Read 507 times)

julkas

  • Hero Member
  • *****
  • Posts: 524
  • KISS principle / Lazarus 2.0.6 / FPC 3.0.4
[SOLVED] Default behavior of C like operators
« on: December 06, 2019, 01:15:52 pm »
From here - https://www.freepascal.org/docs-html/current/prog/progsu10.html
By default, these assignments are not allowed.

But on Raspi following code compiles without problems -
Code: Pascal  [Select]
  1. program cop;
  2. {$mode delphi}
  3. var
  4.   i: integer;
  5. begin
  6.   i := 0;
  7.   i += 1;
  8. {$ifndef EMBEDDED}
  9.   WriteLn(i);
  10. {$endif}
Output -
Code: Text  [Select]
  1. # fpc cop.pas
  2. Free Pascal Compiler version 3.0.0+dfsg-11+rpi1+deb9u1 [2017/07/27] for arm
  3. Copyright (c) 1993-2015 by Florian Klaempfl and others
  4. Target OS: Linux for ARMHF
  5. Compiling cop.pas
  6. Assembling cop
  7. Linking cop
  8. /usr/bin/ld.bfd: warning: link.res contains output sections; did you forget -T?
  9. 10 lines compiled, 2.5 sec
  10.  

Same on Windows with FPC 3.0.4.  Please, clear.
« Last Edit: December 06, 2019, 01:33:18 pm by julkas »
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7862
Re: Default behavior of C like operators
« Reply #1 on: December 06, 2019, 01:23:47 pm »
Probably the switch is in the fpc.cfg file then. Afaik many *nix packages do it by default (which IMHO it shouldn't).

But {$mode should reset it ?
« Last Edit: December 06, 2019, 02:02:23 pm by marcov »

julkas

  • Hero Member
  • *****
  • Posts: 524
  • KISS principle / Lazarus 2.0.6 / FPC 3.0.4
Re: Default behavior of C like operators
« Reply #2 on: December 06, 2019, 01:32:41 pm »
Probably the switch is in the fpc.cfg file then. Afaik many *nix packages do it by default (which IMHO it shouldn't).

But {$mode should rest it ?

Yes. On Raspi and Windows fpc.cfg has -  -Sgic
Thanks.
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;

PascalDragon

  • Hero Member
  • *****
  • Posts: 905
  • Compiler Developer
Re: Default behavior of C like operators
« Reply #3 on: December 07, 2019, 11:30:47 am »
Probably the switch is in the fpc.cfg file then. Afaik many *nix packages do it by default (which IMHO it shouldn't).

But {$mode should reset it ?
No, {$mode XXX} only resets {$modeswitch XXX} parameters. {$COperators XXX} is a different beast. And -Sc is enabled by default in the Windows fpc.cfg as well.