PicoMite V6.00.02 release candidates - all versions


Author Message
toml_12953
Guru

Joined: 13/02/2015
Location: United States
Posts: 570
Posted: 07:23am 07 Jun 2025      

  JohnS said  
  phil99 said  
  Quote  When calling a subroutine you can supply less than the required number of values and in that case the missing values will be assumed to be either zero or an empty string.
BYVAL appears not to adhere to that.
> LIST
' Test prog 1
Dim integer a=5, b=6, c=7
 Print "a, b, c =";a;b;c
test a,,c

Sub test(BYVAL a, BYVAL b, BYVAL c)
If a = 5 Then
 a = 10
 Print "In Sub a, b, c =";a;b;c
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
>


Oops - looks like a bug in MMBasic!

(b should default to 0 in test.)

John


It doesn't look like a bug to me. Variables that aren't passed are global unless declared as LOCAL. The variable b wasn't passed so it retained its value of 6. Try changing b in the sub and see what happens. It will have the changed value after exiting the sub.