Page 1 of 1

Either change the way this works or cause compiler warning

Posted: Sun Mar 10, 2013 8:48 pm
by Joakim Christiansen
The code below will to most coders be quite confusing, this is because this line

Code: Select all

myArray(myRandom(9)) + 1
actually calls the function myRandom() two times.

My suggestion is either that the compiler is changed so this can not occur or that it gives the user a compiler warning informing that this may cause a unexpected result.

This is previously discussed here:
http://www.purebasic.fr/english/viewtop ... =4&t=34908

Code: Select all

EnableExplicit

Procedure myRandom(number)
  number = Random(number)
  Debug "random number generated = "+Str(number)
  ProcedureReturn number
EndProcedure

Define Dim myArray(9), i, x
For i=0 To 9
  myArray(i) = i
Next

RandomSeed(0)
x = myRandom(9)
Debug "Expected output: "+Str(myArray(x)+1)

RandomSeed(0) ;give it the same starting point as above
myArray(myRandom(9)) + 1
Debug "Actual output: "+Str(myArray(x))

Re: Either change the way this works or cause compiler warni

Posted: Sun Mar 10, 2013 8:59 pm
by luis
I don't like how it was implemented either -> http://www.purebasic.fr/english/viewtop ... 95#p390395

The explanation in the manual also as far as I can tell isn't changed -> http://www.purebasic.fr/english/viewtop ... 30#p392530

Before adding any more warning, I would like some more control for them to make them useful and not annoying -> http://www.purebasic.fr/english/viewtop ... 47#p401547

For now, warnings just continue to be repeated, all, at every compilation. So I'm totally against any more warning until this changes -> http://www.purebasic.fr/english/viewtop ... =3&t=53421 or the popping message boxes are converted to simple lines in the log.