Ooops
July 26, 2021, 14:36:20

Author Topic: For local i:INT=0 to 9 Difference in BlitzMax NG and BlitzMax 1.50?  (Read 120 times)

Offline Midimaster

  • Sr. Member
  • ****
  • Posts: 329
    • Midimaster Music Education Software
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
  1. Method Send(AudioArray:Int[])
  2.         Local ShortArray:Short[]
  3.                 Select InFormat
  4.                         Case SF_MONO8                                    
  5.                                         ShortArray= New Short[AudioArray.Length*2]
  6.                                         For Local i%=0 To AudioArray.Length-1
  7.                                                 .....
  8.                                         Next
  9.                         Case SF_STEREO8
  10.                                         ShortArray= New Short[AudioArray.Length]
  11.                                         For Local i%=0 To AudioArray.Length-1
  12.                                                 ....
  13.                                         Next
  14.                         Case ....
  15.                 End Select
  16.         End Method     
  17.  


When I try to use this function in BlitzMax 1.5 it throws an error during compiling:
Code: [Select]
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
  1. SuperStrict
  2. Local tt:tTyp = New tTyp
  3. tt.Test 0
  4. tt.Test 1
  5. Local TestArray:Int[99]
  6.  
  7. tt.Send TestArray
  8.  
  9. Type tTyp
  10.         Global InFormat%
  11.        
  12.         Method Test(a%)
  13.                 Select a
  14.                         Case 0
  15.                                 For Local i%=0 To 9
  16.                                         Print i
  17.                                 Next
  18.                         Case 1
  19.                                 For Local i%=0 To 9
  20.                                         Print i*10
  21.                                 Next
  22.                 EndSelect  
  23.         End Method
  24.  
  25.         Method Send(AudioArray:Int[])
  26.                 Local ShortArray:Short[]
  27.                 Select InFormat
  28.                         Case SF_MONO8                                    
  29.                                         ShortArray= New Short[AudioArray.Length*2]
  30.                                         For Local i%=0 To AudioArray.Length-1
  31.                                         Next
  32.                         Case SF_STEREO8
  33.                                         ShortArray= New Short[AudioArray.Length]
  34.                                         For Local i%=0 To AudioArray.Length-1
  35.                                         Next
  36.                 End Select
  37.         End Method     
  38. End Type

Does somebody know the reason?

See my current project on PlayStore: 20Tracks-Audio-Player https://play.google.com/store/apps/details?id=midimaster.twentytrackd

Offline Henri

  • Sr. Member
  • ****
  • Posts: 340
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

Offline Midimaster

  • Sr. Member
  • ****
  • Posts: 329
    • Midimaster Music Education Software
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.


See my current project on PlayStore: 20Tracks-Audio-Player https://play.google.com/store/apps/details?id=midimaster.twentytrackd

Offline Derron

  • Hero Member
  • *****
  • Posts: 3613
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

Offline Henri

  • Sr. Member
  • ****
  • Posts: 340
Your welcome :-)

NG is strict by default to prevent bad coding habits.

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

Offline Midimaster

  • Sr. Member
  • ****
  • Posts: 329
    • Midimaster Music Education Software
...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?"
See my current project on PlayStore: 20Tracks-Audio-Player https://play.google.com/store/apps/details?id=midimaster.twentytrackd

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal