Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FYI FUNCTIONs and RETURN value
#1
I have seen a problem where if you call a function without a RETURN 0 with no return value in FUNCTION declaration e.g.

FUNCTION UFNprintText(printText$ AS STRING )

Sometimes the function will just crash the ZX Spectrum emulator

Adding a RETURN 0 makes it work.

Just thought you might know this?
Reply
#2
(02-27-2021, 12:07 PM)RandomiserUsr Wrote: I have seen a problem where if you call a function without a RETURN 0 with no return value in FUNCTION declaration e.g.

FUNCTION UFNprintText(printText$ AS STRING )

Sometimes the function will just crash the ZX Spectrum emulator

Adding a RETURN 0 makes it work.

Just thought you might know this?

1) What version are you using?

2) For functions like the above that return numbers, not putting a return will return a random (undefined value) but should never crash the program. If it does, please post a code snippet here to track it. Cool
Reply
#3
(02-28-2021, 05:35 PM)boriel Wrote:
(02-27-2021, 12:07 PM)RandomiserUsr Wrote: I have seen a problem where if you call a function without a RETURN 0 with no return value in FUNCTION declaration e.g.

FUNCTION UFNprintText(printText$ AS STRING )

Sometimes the function will just crash the ZX Spectrum emulator

Adding a RETURN 0 makes it work.

Just thought you might know this?

1) What version are you using?

2) For functions like the above that return numbers, not putting a return will return a random (undefined value) but should never crash the program. If it does, please post a code snippet here to track it. Cool


1) zxbc.py 1.14.1

2) Well I tried to write a small .BAS program to reproduce it but it does not break !
The Function does not return any value 
The output of the compiler generates this error so it seems it needs a value regardless?
Code:
aTest5.bas:16: warning: [W190] Function 'buildVocab' should return a value

This is not a big thing for me as now I simply had a RETURN 0 for functions that don't return a value.

One thing I wonder if returning String Arrays is on the cards sometime soon?
Thank you
Regards
Ken
Reply
#4
(02-28-2021, 05:56 PM)RandomiserUsr Wrote:
(02-28-2021, 05:35 PM)boriel Wrote:
(02-27-2021, 12:07 PM)RandomiserUsr Wrote: I have seen a problem where if you call a function without a RETURN 0 with no return value in FUNCTION declaration e.g.

FUNCTION UFNprintText(printText$ AS STRING )

Sometimes the function will just crash the ZX Spectrum emulator

Adding a RETURN 0 makes it work.

Just thought you might know this?

1) What version are you using?

2) For functions like the above that return numbers, not putting a return will return a random (undefined value) but should never crash the program. If it does, please post a code snippet here to track it. Cool


1) zxbc.py 1.14.1

2) Well I tried to write a small .BAS program to reproduce it but it does not break !
The Function does not return any value 
The output of the compiler generates this error so it seems it needs a value regardless?
Code:
aTest5.bas:16: warning: [W190] Function 'buildVocab' should return a value

This is not a big thing for me as now I simply had a RETURN 0 for functions that don't return a value.

One thing I wonder if returning String Arrays is on the cards sometime soon?
Thank you
Regards
Ken

This is a warning, not an error. For the moment it's just that. In the future, compiling with --strict will issue an error and the program won't compile unless you supply a return value.
Reply
#5
(02-28-2021, 05:56 PM)RandomiserUsr Wrote: One thing I wonder if returning String Arrays is on the cards sometime soon?
Thank you
Regards
Ken

You can use ByRef Array() in functions and subs and return a result there. Returning arrays is on the ToDo list as this require to enable Dyamic Arrays.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)