Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:40 08 Jul 2025 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 : Library anomaly?

Author Message
MikeO
Senior Member

Joined: 11/09/2011
Location: Australia
Posts: 275
Posted: 09:25pm 14 Aug 2016
Copy link to clipboard 
Print this post

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
>
Edited by MikeO 2016-08-16
Codenquilts
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10223
Posted: 09:39pm 14 Aug 2016
Copy link to clipboard 
Print this post

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: Australia
Posts: 275
Posted: 10:06pm 14 Aug 2016
Copy link to clipboard 
Print this post

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
 
Print this page


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

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025