[Gambas-user] Error (or not logic) in sub/function parsing
Benoît Minisini
gambas at ...1...
Mon Nov 22 12:28:15 CET 2010
> Copy the following code in a sample form and run it:
>
> PUBLIC SUB Form_Open()
> DIM a AS Integer
>
> a = Test_sub()
> PRINT a
> a = Test_func()
> PRINT a
>
> END
>
> PUBLIC SUB Test_sub() AS Integer
> RETURN 1
> END
>
> PUBLIC FUNCTION Test_func() AS Integer
> RETURN 1
> END
>
>
> You'll see two "1" in the Gambas console. I think this is wrong because
> a SUB (or Procedure) must not return any value. Instead the Function
> works correctly as it is (or it should be) the only one that can (or
> could) return a value.
>
> The right way should be that Gambas parser should raise an error when it
> finds a "RETURN" statement inside a SUB routine.
But the more practical there is being flexible.
So, as soon as you specify a return type, the compiler assumes your code is a
function, whatever keyword you use: FUNCTION, SUB or PROCEDURE.
Regards,
--
Benoît Minisini
More information about the User
mailing list