Recent

Author Topic: Variables as indexes of arrays (Solved)  (Read 2819 times)

Nitorami

  • Hero Member
  • *****
  • Posts: 507
Re: Variables as indexes of arrays
« Reply #15 on: March 31, 2023, 01:26:18 pm »
I mean all the settings you find under Options/Compiler. Maybe just make screenprints of tabs Syntax, Generated Code and Processor. Or post your fp.cfg file.

JMarques

  • New Member
  • *
  • Posts: 13
Re: Variables as indexes of arrays
« Reply #16 on: March 31, 2023, 03:23:08 pm »
Or post your fp.cfg file.

Here is the content of the fp.cfg: Thanks for your attention.
# Automatically created file, don't edit.
#IFDEF NORMAL
 -TWin32
 -Mfpc
 -Sg
 -Ci
 -O1
 -Cp80386
 -Op80386
 -Rdefault
 -FuC:\FPC\3.2.2\units\$fpctarget
 -FuC:\FPC\3.2.2\units\$fpctarget\*
 -FuC:\FPC\3.2.2\units\$fpctarget\rtl
 -XS
 -g-
 -p-
 -b-
#ENDIF

#IFDEF DEBUG
 -TWin32
 -Mfpc
 -Sg
 -Cr
 -Ci
 -Co
 -Cp80386
 -Op80386
 -Rdefault
 -FuC:\FPC\3.2.2\units\$fpctarget
 -FuC:\FPC\3.2.2\units\$fpctarget\*
 -FuC:\FPC\3.2.2\units\$fpctarget\rtl
 -XS
 -g
 -p-
 -b-
#ENDIF

#IFDEF RELEASE
 -TWin32
 -Mfpc
 -Sg
 -O2
 -Cp80386
 -Op80386
 -Rdefault
 -FuC:\FPC\3.2.2\units\$fpctarget
 -FuC:\FPC\3.2.2\units\$fpctarget\*
 -FuC:\FPC\3.2.2\units\$fpctarget\rtl
 -XS
 -g-
 -p-
 -b-
#ENDIF

Nitorami

  • Hero Member
  • *****
  • Posts: 507
Re: Variables as indexes of arrays
« Reply #17 on: March 31, 2023, 03:44:36 pm »
Very odd. I cannot reproduce this even with your fp.cfg file, and I'm out of ideas. If nothing else helps, maybe try a clean install of the latest version.

Thaddy

  • Hero Member
  • *****
  • Posts: 16132
  • Censorship about opinions does not belong here.
Re: Variables as indexes of arrays
« Reply #18 on: March 31, 2023, 04:33:51 pm »
And what does your fpc.cfg say? Which has always prevalence.
Although I can not see how the compiler settings can be in any way related to your question.
« Last Edit: March 31, 2023, 04:35:22 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

Nitorami

  • Hero Member
  • *****
  • Posts: 507
Re: Variables as indexes of arrays
« Reply #19 on: March 31, 2023, 09:35:44 pm »
Alright, I could identify the conditions under which this happens, and reproduce the issue on a different machine with an AMD processor, FPC 3.2.2, optimization target processor set to 80386, and level 1 optimisation ON, but no other optimisations. It also happens with fpc 3.0.4., but not with 3.3.1. I don't believe it has actively been fixed in 3.3.1, this may just be random.

Faulty output is:
1
2
3
1
2
3
0
0
0
0
1200
0

@JMarques: You can easily get around this, in the IDE under Options/Compiler/Processor just select some newer processor type for optimization, and the problem should be gone forever.

In the meantime, I'll file a bug report. This is a severe issue and should not happen which such a simple code.


JMarques

  • New Member
  • *
  • Posts: 13
Re: Variables as indexes of arrays
« Reply #20 on: March 31, 2023, 11:45:17 pm »
in the IDE under Options/Compiler/Processor just select some newer processor type for optimization, and the problem should be gone forever.

Many many thanks! I am so glad you identified the problem!
But in Options/Compiler I don't find the Processor, I only see Syntax Switches and Compiler mode. as in the attachment, can you enlighten me? Many thanks

Fred vS

  • Hero Member
  • *****
  • Posts: 3409
    • StrumPract is the musicians best friend
Re: Variables as indexes of arrays
« Reply #21 on: April 01, 2023, 12:35:15 am »
in the IDE under Options/Compiler/Processor just select some newer processor type for optimization, and the problem should be gone forever.

Many many thanks! I am so glad you identified the problem!
But in Options/Compiler I don't find the Processor, I only see Syntax Switches and Compiler mode. as in the attachment, can you enlighten me? Many thanks

Hello.

In your fp.cfg, remove all the lines with:

  -Cp80386
 -Op80386


@Nitorami : Well seen!  ;D
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Nitorami

  • Hero Member
  • *****
  • Posts: 507
Re: Variables as indexes of arrays
« Reply #22 on: April 01, 2023, 08:19:33 am »
@JMarques: Your menu looks odd, and tabs are missing. You should see Generated Code, Processor, etc. like in the attached screenshot.

I don't know why that is. Windows 11 ? I also note your awful colors which totally obliterate the purpose of code highlighting in the editor. This happened to me a while ago with a new windows installation, and I literally could not use the console anymore. It turned out that Microsoft had messed up by "modernizing" the console colorscheme which in their opinion came from a time when monitors had poorer contrast than now. While it is true that the colorscheme is old, the reasoning is complete nonsense. The old CRT tube monitors were brighter, faster and had better contrast than now, and there is a reason why professional gamers still use them. You can download MS' "color tool" to reset this shit.

But I still don't know what's wrong with your menu.
« Last Edit: April 01, 2023, 08:34:44 am by Nitorami »

JMarques

  • New Member
  • *
  • Posts: 13
Re: Variables as indexes of arrays
« Reply #23 on: April 01, 2023, 11:29:37 am »
Hello.
In your fp.cfg, remove all the lines with:
 -Cp80386
 -Op80386[/b]

@Nitorami : Well seen!  ;D

Thank you for your attention. I just installed the 3.2.2 32/64 version and the problem was solved!

JMarques

  • New Member
  • *
  • Posts: 13
Re: Variables as indexes of arrays
« Reply #24 on: April 01, 2023, 11:33:57 am »
Alright, I could identify the conditions under which this happens, and reproduce the issue on a different machine with an AMD processor, FPC 3.2.2, optimization target processor set to 80386, and level 1 optimisation ON, but no other optimisations. It also happens with fpc 3.0.4., but not with 3.3.1. I don't believe it has actively been fixed in 3.3.1, this may just be random.
@JMarques: You can easily get around this, in the IDE under Options/Compiler/Processor just select some newer processor type for optimization, and the problem should be gone forever.
In the meantime, I'll file a bug report. This is a severe issue and should not happen which such a simple code.

Nitorani, I just installed the version you have, 3.2.2 32/64 and the problem was solved!!
Thank you very very much for your help! Reproducing the problem was crucial to determine that it wasn't a failure in my hardware.
« Last Edit: April 01, 2023, 11:15:44 pm by JMarques »

JMarques

  • New Member
  • *
  • Posts: 13
Re: Variables as indexes of arrays
« Reply #25 on: April 01, 2023, 11:45:24 am »
@JMarques: Your menu looks odd, and tabs are missing. You should see Generated Code, Processor, etc. like in the attached screenshot.

Nitorami, I figured out the issue. The menu is there but it just doesn't show, the whole menu line is truncated, but I found that I can click on the line and get the corresponding options. Must be a problem with the size or lay out of the box. But it is functional.

I realized that the selected options are still the same as I had in the old version, but even then the program works correctly, so I don't know if I should choose another processor and optimization options, what do you think?

Thank you again!

JMarques

  • New Member
  • *
  • Posts: 13
Re: Variables as indexes of arrays
« Reply #26 on: April 01, 2023, 12:02:49 pm »
In the meantime, I'll file a bug report. This is a severe issue and should not happen which such a simple code.

When I was doing all sorts of crazy tests to figure out the problem I asked the program to write values of row[0][0] to row[0][8], even though row[0] only has three members. Surprizingly, the compiler didn't complain and just printed the nine values. Then I realized that the values for row[0][3] to row[0][5] were actually the values that I had entered for row[1], and the values for row[0][6] to row[0][8] were the values I had attributed to row[2]. Very strange. After I installed the new version and tried to compile the code it immediately pointed out the error in the number of members of row[0].
Perhaps this description can help to better identify the bug.

Nitorami

  • Hero Member
  • *****
  • Posts: 507
Re: Variables as indexes of arrays (Solved)
« Reply #27 on: April 01, 2023, 09:01:01 pm »
I reported it, and Jonas confirmed it is a bug in the peephole optimizer for 80386 processors. I hope a developer will look into that, I can't do it.

And yes, to get reliable results, simply set the optimization target processor to Pentium or some other processor and you'll be fine. Alternatively, turn off O1 optimisation.

 

TinyPortal © 2005-2018