PicoMite V6.00.02 release candidates - all versions


Author Message
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4281
Posted: 11:38am 07 Jun 2025      

  matherp said  
  Quote  Oops - looks like a bug in MMBasic!

(b should default to 0 in test.)


No it isn't. You are just printing the value of a global variable which wasn't passed. Try

' Test prog 1
Dim integer a=5, b=6, c=7
Print "a, b, c =";a;b;c
test a,,c

Sub test(BYVAL x%, BYVAL y%, BYVAL z%)
If x% = 5 Then
x% = 10
Print "In Sub x% y%, z% =";x%;y%;z%
EndIf
End Sub

Print "After Sub a, b, c =";a;b;c
> RUN
a, b, c = 5 6 7
In Sub a, b, c = 10 6 7
After Sub a, b, c = 5 6 7
>


I don't see how that can print In Sub a, b, c = 10 6 7
as it should be In Sub x% y%, z%  etc

But addressing the main issue: normally defining a SUB with parameters makes each of those parameters a sort of locally defined variable, so the original example would have both a global variable b and a parameter b.  The parameter would in effect hide the global one.

It's OK if that is not how MMBasic is supposed to work but it is most unusual/odd.

John
Edited 2025-06-07 21:38 by JohnS