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: AustraliaPosts: 290 |
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 |
||||
WhiteWizzard Guru Joined: 05/04/2013 Location: United KingdomPosts: 2794 |
@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: AustraliaPosts: 3165 |
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. Geoff Geoff Graham - http://geoffg.net |
||||
Print this page |