FAQ  •  Register  •  Login

Function declarations not working (sometimes) (*solved*)

<<

LTee

Posts: 153

Joined: Tue Jul 07, 2009 2:54 pm

Post Tue Jul 22, 2014 8:21 pm

Function declarations not working (sometimes) (*solved*)

Okay, I think I figured out what my other problem is. :)

In 1.3 I could call a function in the code before it was declared providing I declared the function with a prototype at the top of the class. So this would've worked okay, despite the 'addWibble' function appearing after the call to 'addWibble':

  Code:
'function prototypes
declare function addWibble(msg as String) as String

'call addWibble even though it's declared down there vvvv
dim newMsg as String
newMsg = addWibble("Hello")
print newMsg

'return a string suffixed with 'wibble'
function addWibble(msg as String) as String
   dim newString as String
   newString = msg
   newString = newString + "wibble"
   return newString
end function


In 1.4 this won't compile, it seemingly ignores the 'declare' prototype of the function and doesn't recognise 'addWibble' when it first encounters it, giving an error like this:

  Code:
TestFunction.bas:8: 'addWibble' is neither an array nor a function.


If you move the call below function like this then everything is fine:

  Code:
'return a string suffixed with 'wibble'
function addWibble(msg as String) as String
   dim newString as String
   newString = msg
   newString = newString + "wibble"
   return newString
end function

'call addWibble even though it's declared down there vvvv
dim newMsg as String
newMsg = addWibble("Hello")
print newMsg


HOWEVER.... it's a bit more complicated than that. It seems that I only see this effect if the function returns a String. If I quickly switch the function to return a ubyte instead then everything compiles fine.

  Code:
'function prototypes
declare function addWibble(msg as string) as ubyte

'call addWibble even though it's declared down there vvvv
dim newMsg as ubyte
newMsg = addWibble("test")
print newMsg

'return the number 1
function addWibble(msg as string) as ubyte
   return 1
end function


Hope that makes sense! :D
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Tue Jul 29, 2014 4:20 pm

Re: Function declarations not working (sometimes)

Thanks, LTee.
Will check it ASAP.
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Sat Aug 16, 2014 11:13 pm

Re: Function declarations not working (sometimes)

Ok. It seems fixed now.
Please download ZXBasic-s1893, and tell me if it works.
<<

LTee

Posts: 153

Joined: Tue Jul 07, 2009 2:54 pm

Post Fri Aug 29, 2014 7:06 pm

Re: Function declarations not working (sometimes)

Hi, sorry for the delay - I've been away on my holidays. :)

Just tried the new version out and you'll be pleased to hear I agree - it's working perfectly! In fact I can now compile all of my old code with the latest version without any obvious errors, so that's brilliant! Thanks, boriel!
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Tue Sep 02, 2014 8:41 am

Re: Function declarations not working (sometimes)

LTee wrote:Hi, sorry for the delay - I've been away on my holidays. :)

Just tried the new version out and you'll be pleased to hear I agree - it's working perfectly! In fact I can now compile all of my old code with the latest version without any obvious errors, so that's brilliant! Thanks, boriel!

Thanks to you for this!! :roll:

Return to Bug Reports

Who is online

Users browsing this forum: No registered users and 2 guests

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.

phpBB SEO