![]() |
Forum Index : Microcontroller and PC projects : MMB4W: Function error, possible bug?
Author | Message | ||||
LeoNicolas![]() Guru ![]() Joined: 07/10/2020 Location: CanadaPosts: 504 |
The following code ends with the error: Error in line 15: FUNC is not declared. option explicit main() sub main() local i% for i%=0 to 4 func1() next end sub function func1() as integer func1=10 end function If I change the code as follows it works fine: option explicit main() sub main() local i%, ret for i%=0 to 4 ret=func1() next end sub function func1() as integer func1=10 end function |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
It's a function so it needs to do something with the return. Because you had no var to accept the return, it went looking for a SUB Jim VK7JH MMedit |
||||
Geoffg![]() Guru ![]() Joined: 06/06/2011 Location: AustraliaPosts: 3292 |
It is tempting to think that something not working as you expected as a bug in the compiler/interpreter - but 99.999% of the time it is not. We all fall into this trap from time to time. Geoff Geoff Graham - http://geoffg.net |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7937 |
Oh yes.... Tell me about it.... :( I'm forever being outsmarted by a bit of silicon! Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
LeoNicolas![]() Guru ![]() Joined: 07/10/2020 Location: CanadaPosts: 504 |
Sorry for my false positive bug post. This is interesting. I can imagine why It happens. Probably the variable pointer is used directly for the func routine to store the return value, instead of having another memory allocation just for holding the value while the function is executed. Of course I can be completely wrong. |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10315 |
Yes. The first thing in a line is always an in-built command or a user SUBROUTINE. A function must always be assigned to something, typically using the in-built command LET which is the default if there is an = i.e. ret=func1() is actually interpreted ad LET ret=func1() Func1() at the start of a line fails the interpreter lookup for either an in-built command or a use subroutine hence the error |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |