Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 02:15 30 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : variable, function and sub

Author Message
ajkw
Senior Member

Joined: 29/06/2011
Location: Australia
Posts: 290
Posted: 01:43am 26 Nov 2014
Copy link to clipboard 
Print this post

I came across this in some development and I am not sure if the behaviour in the first example is correct or not. I hope you can follow it but it seems a variable that is passed to a sub is not passed to a subsequent sub(function(variable)).

[Micromite 4.5D]

with the following code I get the output

10
finalout 0
'this output I feel is incorrect expected 10
finalout 1

anum = 1
test(anum)
write(anum)
End

Sub test(tt)
Print mult(tt)
write(mult(tt))
End Sub

Function mult(inp)
mult = inp*10
End Function

Sub write(finalout)
Print "finalout";finalout
End Sub


while with the following I get the output

10
finalout 10
finalout 1


anum = 1
test ''''(anum)
write(anum)
End

Sub test ''''(tt)
tt = anum
Print mult(tt)
write(mult(tt))
End Sub

Function mult(inp)
mult = inp*10
End Function

Sub write(finalout)
Print "finalout";finalout
End Sub
Edited by ajkw 2014-11-27
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 05:46am 26 Nov 2014
Copy link to clipboard 
Print this post

@ajkw

It does seem incorrect - probably treating multi(tt) as an array element in error (hence the unexpected value of zero).

However - that said, I can confirm it is correct in the latest Beta firmware that is currently under development by Geoff Graham. This may not help you immediately - BUT it has at least been identified and corrected.

I am not in a position to say when Geoff will publicly make the next version available - but as you are on the BSF, you can apply for Beta testing and Geoff should be ok with adding you to his 'team'.

Hope this is of some help . . . .

WW
For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 05:21pm 26 Nov 2014
Copy link to clipboard 
Print this post

Yes, there is an issue with using a function in the argument list when calling another function or subroutine - which is what your code (listed below) does:
Sub test(tt)
Print mult(tt)
write(mult(tt))
End Sub

Note the text in bold.

To avoid issues like this you need to not use user defined functions in the argument list. Instead call the function separately and assign the result to a temporary variable. Then you can use the temporary variable when calling the subroutine. For example:
Sub test(tt)
Local temp
Print mult(tt)
temp = mult(tt)
write temp
End Sub


The fix for this has been incorporated in the latest beta for the Micromite MkII. When the beta test period is over I plan to go back to the original Micromite code (running on the MX150) and incorporate any fixes like this.

GeoffEdited by Geoffg 2014-11-29
Geoff Graham - http://geoffg.net
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024