Recent

Author Topic: likely bug in FPC v3.2.2  (Read 1015 times)

440bx

  • Hero Member
  • *****
  • Posts: 4732
likely bug in FPC v3.2.2
« on: July 20, 2024, 12:40:08 am »
Hello,

Consider this code:
Code: Pascal  [Select][+][-]
  1. {$APPTYPE CONSOLE}
  2.  
  3. program _ComparisonOperators;
  4.  
  5. var
  6.   ADword, AnotherDword : DWORD;
  7.  
  8.  
  9. begin
  10.  
  11.   ADword       := $48;
  12.   AnotherDword := $BC;
  13.  
  14.   if ADword >- AnotherDword then
  15.   begin
  16.     writeln(ADword, ' is >- ', AnotherDword, ' (whatever that means!)');
  17.   end;
  18.  
  19.   readln;
  20. end.
Note the likely invalid comparison operator in use ">-", yet the compiler doesn't complain.  Running the program shows the comparison is TRUE.

Comments welcome.

ETA:

As correctly pointed out by GAN below, there is no bug.  The compiler "sees" >- as "greater than minus (whatever follows)" which is correct.
« Last Edit: July 20, 2024, 02:13:57 am by 440bx »
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

GAN

  • Sr. Member
  • ****
  • Posts: 376
Re: likely bug in FPC v3.2.2
« Reply #1 on: July 20, 2024, 01:12:05 am »
Hello, a very simple answer/comment:

I think the compiler replace with integer values before de comparision, so:
Code: Pascal  [Select][+][-]
  1. if ADword 72 > -188 then
  2.  

yes, it is True.
Lazarus 2.0.8 FPC 3.0.4 Linux Mint Mate 19.3
Zeos 7̶.̶2̶.̶6̶ 7.1.3a-stable - Sqlite 3.32.3 - LazReport

440bx

  • Hero Member
  • *****
  • Posts: 4732
Re: likely bug in FPC v3.2.2
« Reply #2 on: July 20, 2024, 01:18:17 am »
Hello, a very simple answer/comment:

I think the compiler replace with integer values before de comparision, so:
Code: Pascal  [Select][+][-]
  1. if ADword 72 > -188 then
  2.  

yes, it is True.
You are absolutely right.  I didn't think of that and, now that you've pointed it out, it looks obvious.

Thank you!

Conclusion: no bug in the compiler.  bug in OP's brain that caused incorrect expression parsing ;)
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018