![]() |
Forum Index : Microcontroller and PC projects : Library anomaly?
Author | Message | ||||
MikeO Senior Member ![]() Joined: 11/09/2011 Location: AustraliaPosts: 275 |
I have come across this unexpected library behavior. I wanted to create some variables and constants that are specific to items in a library I am creating and put them in a sub routine also stored in the library. I could then just initialise them by running the a sub "Declares" in my start up code in main memory. I have found however that constants seem not to work but Dim variables are OK. All the variables including the Constants are allocated as can be seen from the Memory command and also you get an error as expected if you try to re-instate them. Constants created from the command prompt work as expected ofcourse. I created a little test shown below. It simply stores a sub "Declares" in the library, shows that it is loaded, shows that Constants and Dim Variables behave differently,Dim Variable prints OK but Constant does not, shows they are present in Ram, shows a constant created at the command prompt works as expected. I could just created them as Dim Variables, I realise. > Micromite MKII MMBasic Ver 5.2
Copyright 2011-2016 Geoff Graham > library list Sub Declares Const Ver$="1.4" Dim Ver1$="1.8" Const Topval=2000 End Sub > declares > print ver$ > print ver1$ 1.8 > print topval 0 > memory Flash: 0K ( 0%) Program (0 lines) 1K ( 1%) Library 59K (99%) Free RAM: 1K ( 1%) 3 Variables 0K ( 0%) General 49K (99%) Free > const ver2$="2.3" > print ver2$ 2.3 > Codenquilts |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10223 |
Mike This is as documented in the manual. "A constant defined outside a sub or function is global and can be seen throughout the program. A constant defined inside a sub or function is local to that routine" This was the subject of some discussion with Geoff and there are clear arguments both for and against but without separate definition of global and local constants a choice had to be made. |
||||
MikeO Senior Member ![]() Joined: 11/09/2011 Location: AustraliaPosts: 275 |
Oh Blow, OK thanks for that I had missed it but I suspected it had been covered. I will have to go with Variables. Thanks again. Codenquilts |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |