|
Forum Index : Microcontroller and PC projects : MMbasic Interpreter bug? [with OPTION DEFAULT]
| Author | Message | ||||
| MustardMan Senior Member Joined: 30/08/2019 Location: AustraliaPosts: 175 |
Hi, When using OPTION DEFAULT NONE to enforce good programming habits (everything must be properly defined), I get an error with EXIT FOR. I have attached the relevant code snippet below: OPTION EXPLICIT ' All varibles must be explicitly defined before use OPTION DEFAULT NONE ' And all variables must have their type explicitly defined too CONST params = 16 ' It seems constants can't have their type specified (??) DIM INTEGER n ' General use FOR n = params TO 1 STEP -1 ' Check backwards: no touch results in n=0 IF CheckPress(n) THEN EXIT FOR ' Exit FOR loop early if a touch is detected NEXT n ' n = index (0 = no touch, or touch in wrong area) The "button" check is done backwards resulting in a non-button area touch being zero. This is easier to deal with (in a program) than checking for '= params+1' or '> params'. The error thrown is: [119] If CheckPress(n) Then Exit For Error: Variable type not specified If I comment out the OPTION DEFAULT line, it works fine. Interpreter version output with "? MM.VER" is 5.0502, and it is running on a MicroMite Explore 100. As a side note, I was not able to define the type of a constant (tried AS INTEGER, INTEGER, before, after, used DIM, no luck). Can I not define the type of a constant? Cheers, |
||||
| Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3308 |
I could not get this to fail (Ver 5.05.02). Perhaps there is something going wrong in the function CheckPress() that is causing MMBasic to report an error in the wrong place. This is the test code that I used: OPTION EXPLICIT ' All varibles must be explicitly defined before use OPTION DEFAULT NONE ' And all variables must have their type explicitly defined too CONST params = 16 ' It seems constants can't have their type specified (??) DIM INTEGER n ' General use FOR n = params TO 1 STEP -1 ' Check backwards: no touch results in n=0 IF CheckPress(n) THEN EXIT FOR ' Exit FOR loop early if a touch is detected NEXT n Function CheckPress(a as integer) as integer CheckPress = 0 End Function On your second point. Yes, you are supposed to be able to specify the type of a constant. But doing that caused an error in your test code. I will add this to the bug list for the next version. Geoff Geoff Graham - http://geoffg.net |
||||
| Turbo46 Guru Joined: 24/12/2017 Location: AustraliaPosts: 1646 |
Geoff, I quickly tried MustardMan's program and it failed because CheckPress was not specified. It says several times in the manual that a CONST defaults to the implied data type: So for that reason I thought it is not necessary to specify the type of a constant? Bill Keep safe. Live long and prosper. |
||||
| MustardMan Senior Member Joined: 30/08/2019 Location: AustraliaPosts: 175 |
@Turbo46 My apologies, I will post more of the program this-evening when I get home. I suppose thinking there might be a bug does call for a bit more than a tiny snippet of code! As Geoffg has pointed out, it may well be the definition of "CheckPress()" that is my problem. I did read in the manual that constants were typed by the value that they were given, which is fine, and really easy. Coming from a C background where things are much 'tighter', I did not think of trying symbols when specifying a constant. I instinctively thought to "word" it (eg: FLOAT) rather than "symbolise" it (eg: $) to make it something in particular. Cheers, |
||||
| Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3308 |
I have since checked the manual and it does indeed support the current behaviour. However, to me it would be more consistent if CONST supported full typing like DIM. From memory that part of the code was complex and maybe that is why full typing did did not make it in. Anyway, I will investigate. Geoff Geoff Graham - http://geoffg.net |
||||
| Turbo46 Guru Joined: 24/12/2017 Location: AustraliaPosts: 1646 |
I'm sorry too MustardMan. I assumed that your snippet was expected to show the problem as was. Geoff knew better on both points of course. I was writing my post when his popped up. I probably should have deleted the contents and shut up. Bill PS. It happened again! Keep safe. Live long and prosper. |
||||
| MustardMan Senior Member Joined: 30/08/2019 Location: AustraliaPosts: 175 |
@Turbo46 and @Geoffg Well, I do feel stupid - Geoff was spot on with his diagnosis, it was the definition of 'CheckPress()'. The original: FUNCTION CheckPress (n AS INTEGER) LOCAL INTEGER x = TOUCH(x) LOCAL INTEGER y = TOUCH(y) blah blah And the way it should be, and working... FUNCTION CheckPress (n AS INTEGER) AS INTEGER LOCAL INTEGER x = TOUCH(x) LOCAL INTEGER y = TOUCH(y) blah blah With regard to constants: it is not an issue, I just wondered if it was supposed to support word definitions or not, and 'not' it is! Cheers, and many thanks!!! |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |