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 : Local variable size limit
Author | Message | ||||
BobDevries Senior Member Joined: 08/06/2011 Location: AustraliaPosts: 266 |
Hi all, is there a limit toi the size of LOCAL variables in functions? I'm getting an error: stack overflow. Expression is too complex. The code: Function fkey(funkey) Local F$,I$ F$=Chr$(145)+Chr$(146)+Chr$(147)+Chr$(148)+Chr$(149)+Chr$(15 0)+Chr$(151) F$=F$+Chr$(152)+Chr$(153)+Chr$(154)+Chr$(155)+Chr$(156) key: I$=Inkey$:If I$="" GoTo key funkey = Instr(1,F$,I$) Return What am I doing wrong? Regards, Bob Devries Dalby, QLD, Australia |
||||
BobD Guru Joined: 07/12/2011 Location: AustraliaPosts: 935 |
Typo? Chr$(15 0)extra space should that be Chr$(150) ? Bob |
||||
BobDevries Senior Member Joined: 08/06/2011 Location: AustraliaPosts: 266 |
Hi Bob, I checked that, but it seems to be an artifact of cutting and pasting into the forum. There's no space in my code. Regards, Bob Devries Dalby, QLD, Australia |
||||
bigmik Guru Joined: 20/06/2011 Location: AustraliaPosts: 2914 |
I would expect that that problem would be the infamous `The Bad Shed' Add extra spaces to long lines (that arent broken by a space) Regards, Mick Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<< |
||||
BobDevries Senior Member Joined: 08/06/2011 Location: AustraliaPosts: 266 |
Hi All, even if I remove the line that declares the LOCAL variables, I then get the same error on the line: key: I$=inkey$:if I$="" then goto key Have I unearthed a (dare I say it?) bug? Or am I doing something basically (pun intended) wrong? Regards, Bob Devries Dalby, QLD, Australia |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
Bob, I think I had this problem some time ago - try putting the label on a separate line, key:
I$=inkey$:if I$="" goto key Greg |
||||
BobDevries Senior Member Joined: 08/06/2011 Location: AustraliaPosts: 266 |
Ah, now that you mention it.... I'll give that a try. Regards, Bob Devries Dalby, QLD, Australia |
||||
BobDevries Senior Member Joined: 08/06/2011 Location: AustraliaPosts: 266 |
Hi Greg & all, Yep, that works now. Strange thing is... if I put the same line as inline in the main body of the programme, no error is generated. Go figure. Regards, Bob Devries Dalby, QLD, Australia |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3194 |
Bob, This is the first time that I have seen someone hit the "stack overflow" error. It is not caused by a local variable being too big - local variables have exactly the same rules as normal variables. What happens is that the interpreter evaluates an expression by recursively calling itself and while doing that it saves temporary values onto the stack. The stack overflow error means that the expression is so complex that the interpreter has used up all the RAM reserved for the stack. The problem here is that the expressions in the sample program are not nearly complex enough to cause this error. Also the loop at the label "key:" could not be causing a stack overflow because there is no complex expression there either. I tried running the program but it does not run and it does not make any sense. You declare a function but there is no END FUNCTION statement, instead you use RETURN when there is no GOSUB to return to. I suspect that it is this mangled code that is somehow tripping up the interpreter which then runs off the rails causing the stack overflow error. Geoff Geoff Graham - http://geoffg.net |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
That's probably what I was doing too Geoff. At the time I remember I'd mixed up various combinations of "GOSUB", "FUNCTION", "END FUNCTION", "RETURN" and labels (no ":" on them) a couple of times before I fnally got the code working. Greg |
||||
BobDevries Senior Member Joined: 08/06/2011 Location: AustraliaPosts: 266 |
The final code which works is here: Function fkey() Local F$, I$ F$=Chr$(145)+Chr$(146)+Chr$(147)+Chr$(148)+Chr$(149)+Chr$(15 0)+Chr$(151) F$=F$+Chr$(152)+Chr$(153)+Chr$(154)+Chr$(155)+Chr$(156) F$=F$+"Q"+"q" key: I$=Inkey$:If I$="" Then GoTo key fkey=Instr(1,F$,I$) End Function @Geoff: You're probably right about what really caused the error. I had mixed up the function/end function with Gosub/Return. I'd say the interpreter got confused; I know I was :P Regards, Bob Devries Dalby, QLD, Australia |
||||
Print this page |