[Windows 4.3 B4] Really strange bug with arrays

Post bugreports for the Windows version here
User avatar
RocketRider
User
User
Posts: 87
Joined: Tue Aug 19, 2008 11:01 am

[Windows 4.3 B4] Really strange bug with arrays

Post by RocketRider »

Really strange bug with arrays

Code: Select all

Global Count

Procedure.l Number(Max.l)
lResult.l = Count
Count + 1
ProcedureReturn lResult % Max
EndProcedure


Dim counts(10)

For i=0 To 1000
counts(Number(10)) + 1
;The following works
;x = Number(10)
;counts(x) + 1
Next

For n=0 To 9
Debug counts(n)
Next
User avatar
Deeem2031
Enthusiast
Enthusiast
Posts: 216
Joined: Sat Sep 20, 2003 3:57 pm
Location: Germany
Contact:

Post by Deeem2031 »

irc://irc.freenode.org/#purebasic
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

KMA! :shock:

... really strange, and I never before heard of it ...

I wonder why I never happened to fall into that pit...
oh... and have a nice day.
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Post by ABBKlaus »

no bug, the procedure Number() is called twice.

ASM Code :

Code: Select all

  PUSH   dword 10
  CALL  _Procedure0 ; <- first call to Number()
  MOV    ebx,eax
  MOV    ebp,dword [a_counts]
  SAL    ebx,2
  MOV    ebx,dword [ebp+ebx]
  INC    ebx
  PUSH   ebx
  PUSH   dword 10
  CALL  _Procedure0 ; <- second call to Number()
  MOV    ebx,eax
  MOV    ebp,dword [a_counts]
  SAL    ebx,2
  POP    dword [ebp+ebx]
The short writing of the code

Code: Select all

counts(Number(10)) + 1
is expanded to this

Code: Select all

counts(Number(10))=counts(Number(10)) + 1
User avatar
Deeem2031
Enthusiast
Enthusiast
Posts: 216
Joined: Sat Sep 20, 2003 3:57 pm
Location: Germany
Contact:

Post by Deeem2031 »

Yea, thats the same we found out in the old thread, but its still a bug because it's not intentional if you write the short version.
irc://irc.freenode.org/#purebasic
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

Deeem2031 wrote:but its still a bug because it's not intentional if you write the short version.
Yeah, because how would anyone (normal users) know about this behavior? This is clearly not what a user wants.
I like logic, hence I dislike humans but love computers.
Post Reply