Recent

Author Topic: Difference between += and := -- Is this a bug in FPC?  (Read 13787 times)

munair

  • Hero Member
  • *****
  • Posts: 798
  • compiler developer @SharpBASIC
    • SharpBASIC
Re: Difference between += and := -- Is this a bug in FPC?
« Reply #15 on: October 18, 2017, 04:15:58 pm »
@ It looks like it has to do with the combination of object referencing.

No. It has to do with properties. Operator += needs variable. Setters and getters have no address.
It seems that CurrentString from the original post is a property.
Object properties are referenced / dereferenced during execution, if I'm not mistaken. So the problem is referencing as opposed to variable address.
keep it simple

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Difference between += and := -- Is this a bug in FPC?
« Reply #16 on: October 18, 2017, 07:54:24 pm »
In this case, the two should be identical. Can you make a super simple example that still reproduce this issue so that we can confirm?

Consider the following program:
Code: Pascal  [Select][+][-]
  1. program minimal;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses {$IFDEF UNIX} {$IFDEF UseCThreads}
  6.   cthreads, {$ENDIF} {$ENDIF}
  7.   Classes { you can add units after this };
  8.  
  9. var
  10.   boolVar: boolean = True;
  11.   SomeVar: integer = 0;
  12. begin
  13.   if boolVar then
  14.     SomeVar += 1
  15.   else
  16.     SomeVar := SomeVar - 1;
  17. end.

When you debug this program it should start at
Code: Pascal  [Select][+][-]
  1.   if boolVar then
then:
Code: Pascal  [Select][+][-]
  1.     SomeVar += 1
and finally:
Code: Pascal  [Select][+][-]
  1. end.
That is the expected behavior. BUT the current behavior is different at the second step. Instead of showing 
Code: Pascal  [Select][+][-]
  1.     SomeVar += 1
it shows:
Code: Pascal  [Select][+][-]
  1.   else

If you replace += with the full syntax  SomeVar := SomeVar + 1 you will see the correct expected behavior.



Here is GDB output when using C operator:
Quote
13        if boolVar then
(gdb) n
15        else
(gdb)
17      end.
(gdb)


Here is GDB output *without* C operator:
Quote
13        if boolVar then
(gdb) n
14          SomeVar := SomeVar + 1
(gdb)
17      end.
(gdb)

munair

  • Hero Member
  • *****
  • Posts: 798
  • compiler developer @SharpBASIC
    • SharpBASIC
Re: Difference between += and := -- Is this a bug in FPC?
« Reply #17 on: October 18, 2017, 08:15:11 pm »
@engkin, there seem to be two issues here (at least).

1. The debugger does not fully support C-style operators.

2. C-style operators can only be used with simple variables. As demonstrated in an earlier comment, C-style operators won't work with object properties.
keep it simple

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Difference between += and := -- Is this a bug in FPC?
« Reply #18 on: October 18, 2017, 08:38:40 pm »
@engkin, there seem to be two issues here (at least).

1. The debugger does not fully support C-style operators.

The debugger knows what FPC saved in the debug information. IAW, FPC generates wrong debug information for C operators. Specifically, wrong line number.

munair

  • Hero Member
  • *****
  • Posts: 798
  • compiler developer @SharpBASIC
    • SharpBASIC
Re: Difference between += and := -- Is this a bug in FPC?
« Reply #19 on: October 18, 2017, 09:56:54 pm »
@engkin, there seem to be two issues here (at least).

1. The debugger does not fully support C-style operators.

The debugger knows what FPC saved in the debug information. IAW, FPC generates wrong debug information for C operators. Specifically, wrong line number.
Yes, thanks for correcting me there. Suffice it to say, better not use C-style operators.
« Last Edit: October 18, 2017, 09:58:47 pm by Munair »
keep it simple

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Difference between += and := -- Is this a bug in FPC?
« Reply #20 on: October 19, 2017, 04:36:06 am »
@engkin, there seem to be two issues here (at least).

1. The debugger does not fully support C-style operators.

The debugger knows what FPC saved in the debug information. IAW, FPC generates wrong debug information for C operators. Specifically, wrong line number.
Yes, thanks for correcting me there. Suffice it to say, better not use C-style operators.

What if this bug is not limited to C operators?

I believe this bug should be reported.

EganSolo

  • Sr. Member
  • ****
  • Posts: 290
Re: Difference between += and := -- Is this a bug in FPC?
« Reply #21 on: October 19, 2017, 05:42:27 am »
Don't use C-style operators. Got it.

So... should I report this or will someone else do it? I'm fine either way. I just want to know :)

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Difference between += and := -- Is this a bug in FPC?
« Reply #22 on: October 19, 2017, 05:57:19 am »
Yes, please do. Otherwise it will be forgotten.

schuler

  • Full Member
  • ***
  • Posts: 223
Re: Difference between += and := -- Is this a bug in FPC?
« Reply #23 on: October 25, 2017, 12:39:01 am »
Quick note: Caption is a property (not a variable).

 

TinyPortal © 2005-2018