For local i:INT=0 to 9 Difference in BlitzMax NG and BlitzMax 1.50?

Started by Midimaster, July 14, 2021, 12:24:04

Previous topic - Next topic

Midimaster

I try to create a common source for my RingbufferClass. I managed all problems except one "very strange"

Inside the Typ RingbufferClass I have a methode Send(Data:Int[]) which has different procedures to handle the datas.
So I use SELECT/CASE/ENDSELECT for the variations. Inside the CASEs I need a FOR/NEXT-LOOP.

On BlitzMaxNG I use local variables i for the loop and this works perfect:
Code (BlitzMax) Select
Method Send(AudioArray:Int[])
Local ShortArray:Short[]
Select InFormat
Case SF_MONO8
ShortArray= New Short[AudioArray.Length*2]
For Local i%=0 To AudioArray.Length-1
.....
Next
Case SF_STEREO8
ShortArray= New Short[AudioArray.Length]
For Local i%=0 To AudioArray.Length-1
....
Next
Case ....
End Select
End Method


When I try to use this function in BlitzMax 1.5 it throws an error during compiling:
Compiling:RingBufferClassFinal.bmx
Compile Error: Duplicate identifier 'i'
[C:/Basic/RingBuffer/RingBufferClassFinal.bmx;148;6]
Build Error: failed to compile C:/Basic/RingBuffer/RingBufferClassFinal.bmx


But when I code this test-app it works perfect:
Code (BlitzMax) Select
SuperStrict
Local tt:tTyp = New tTyp
tt.Test 0
tt.Test 1
Local TestArray:Int[99]

tt.Send TestArray

Type tTyp
Global InFormat%

Method Test(a%)
Select a
Case 0
For Local i%=0 To 9
Print i
Next
Case 1
For Local i%=0 To 9
Print i*10
Next
EndSelect 
End Method

Method Send(AudioArray:Int[])
Local ShortArray:Short[]
Select InFormat
Case SF_MONO8
ShortArray= New Short[AudioArray.Length*2]
For Local i%=0 To AudioArray.Length-1
Next
Case SF_STEREO8
ShortArray= New Short[AudioArray.Length]
For Local i%=0 To AudioArray.Length-1
Next
End Select
End Method
End Type


Does somebody know the reason?

...back from Egypt

Henri

Hi,

this is a strict vs. non-strict issue.

If you define your code to be strict or superstrict then your 'for next' block has it's own local scope, and can have the same variable name in the iterator. Otherwise you get an error about duplicate identifiers.

Just as a note, you can use 'Until' keyword to replace the 'To' keyword and you don't have to add the -1 at the end.

-Henri
- Got 01100011 problems, but the bit ain't 00000001

Midimaster

Oh! I did not know that!
I always thought  that the whole code is Superstrict when I define Superstrict in the main file.

I tested, what you said and you are right. A second SuperStrict on top of the second file RingbufferClass.bmx resolves the problems.

Now I think I have found, why I never had  this problem before... Its because I added the second code with "Import RingbufferClass.bmx" and not with "Include RingbufferClass.bmx". When I use Include, the SuperStrict seems to have a sccope over all code.

But this means also, that BlitzMax NG has changed this. In BlitzMax NG the Superstrict of the main file seems to act also on the sub files includes with Import RingbufferClass.bmx? Here I get no error messages.

Thanks a lot, Henri.


...back from Egypt

Derron

how should the imported file in NG or vanilla know wether the "parent" is superstrict or not?
they are compiled without "knowledge" of the parent.

Same to say for modules. So a non-superstrict module in vanilla does not become superstrict just because your application is superstrict.


Include -- the code in the included file is copied into the file at the include position, so it acts like a placeholder - of course superstrict would be applied then, if the including file is superstrict.


bye
Ron

Henri

Your welcome :-)

NG is strict by default to prevent bad coding habits.

-Henri
- Got 01100011 problems, but the bit ain't 00000001

Midimaster

Quote from: Henri on July 15, 2021, 08:09:50
...NG is strict by default to prevent bad coding habits.

Thanks Henri, you are so fast! This answers my question, before I could send it: "Why  does it work anyway in BlizMax NG?"
...back from Egypt