Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 13:47 17 Sep 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 : uM2(+): Weird bug to be aware of

Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10400
Posted: 11:44pm 22 Aug 2016
Copy link to clipboard 
Print this post

I've now been able to simply demonstrate the bug which I think is the problem in these threads.

Thread 1

Thread 2

The bug is definitely in both versions 5.1 and 5.2. I've let Geoff know separately.

Basically there is some strange interaction between
OPTION EXPLICIT
OPTION AUTORUN ON
and
CONST and LOCAL when used in MM.STARTUP

To demonstrate the bug load the following test program

Option explicit
option default NONE
option autorun on
dim integer e=4
print e
pause 1000
end
Sub mm.startup
Const a=2
Local integer b=a\2
print b
End Sub


type CPU RESTART and MM.STARTUP will execute as expected and print "1"
type RUN and the main program will run as expected and print "4". This of course also enables autorun

Now type CPU RESTART again. We expect MM.STARTUP to run and then the main program to run. MM.STARTUP runs and prints "1" but the main program fails with the error

  Quote  [1] Option explicit
Error: Variables already defined


Here is the full trace

  Quote  
> list
Option explicit
Option default NONE
Option autorun on
Dim integer e=4
Print e
Pause 1000
End
Sub mm.startup
Const a=2
Local integer b=a\2
Print b
End Sub
> cpu restart
1
> run
4
> cpu restart
1
[1] Option explicit
Error: Variables already defined
>



The following also gives the bug:

Sub mm.startup
local integer a=2
Local integer b=a\2
print b
End Sub


Note if you change MM.STARTUP to

[code]Sub mm.startup
Const a=2
print a\2
End Sub[/code]

The bug no longer happens

  Quote  
> list
Option explicit
Option default NONE
Option autorun on
Dim integer e=4
Print e
Pause 1000
End
Sub mm.startup
Const a=2
Print a\2
End Sub
> cpu restart
1
> run
4
> cpu restart
1
4
>












Edited by matherp 2016-08-24
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2447
Posted: 03:22am 23 Aug 2016
Copy link to clipboard 
Print this post

the following code also fails:

a=2
Option EXPLICIT


from the 5.2 manual:
  Quote  The use of OPTION EXPLICIT is recommended to support good programming practice. If it is used it should be placed at the start of the program before any variables are used.


if the word "should" is replaced with "MUST", and it is stressed that it needs to be placed in MM.STARTUP if this file is used, is the observed behaviour mitigated?

it kind of makes sense that both of the program spaces need to operate under the same set of 'rules', as they both share the same single variable space. perhaps Option EXPLICIT needs to be changed so that it is aware of already defined variables?


cheers,
rob :-)
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10400
Posted: 05:40am 23 Aug 2016
Copy link to clipboard 
Print this post

  Quote  it is stressed that it needs to be placed in MM.STARTUP if this file is used


This nearly works except that if mm.startup is in the library when you load a new program then the OPTION EXPLICIT isn't active until you restart. See trace below

  Quote  library list
Sub mm.startup
Option explicit
Option default NONE
Const a=2
Local integer b=a\2
Print b
End Sub
> cpu restart
1
>
> 'program loaded
> list
Option autorun on
e=4
Print e
Pause 1000
End
> run
4
> 'that should have failed
> cpu restart
1
[2] e=4
Error: E not declared
> 'now it fails
>



Edited by matherp 2016-08-24
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2447
Posted: 06:55am 23 Aug 2016
Copy link to clipboard 
Print this post

would it help if option explicit was a persistent setting, like option autorun is? it would then become a 'personal style' setting like selecting the colours in an editor, etc.

myself, i never use the library functions, mm.startup or mm.prompt. they make keeping track of what the micromite is doing unnecessarily confusing.


cheers,
rob :-)
 
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