Hi
I find logic the error pointed out by Option _explicit
why?
simple, we using SHARED in closed block like SUB and FUNCTION to pass that inner variable to the main block.
But in the main block there is no definition of that variable which SHARED forced to be, so Option _Explicit does it work to show what is not declared explicitly.
To let work in different style Option _Explicit can give a warn and no halt the compilation because its goal is to give information to the user and not to correct the syntax.
What do you think about this?
Aha! It woiked! The SHARED variable in the sub still needs a declared variable (with the same type) in the main.
But that defeats the whole purpose of using SHARED in subs/functions so you don’t need to declare the variables in the main module, for ease of library usage.
If two subs are passing a variable and value back and forth, isn't it good to make note of that in something global like a BI file? It helps put things out in the open for users unfamiliar with the code to see and be aware of.
Since people are using OPTION _EXPLICIT, SHARED is now a worthless command for SUB and FUNCTION. May as well just DIM SHARED everything and force all libraries to come in two parts, rather than try to code and keep it simple so the end user only needs one *.BM file.
Something is worthless because you have to add a couple more words in a BI file? Sheesh!
IF optionexplicit THEN a$ = "Variable '" + n$ + "' (" + symbol2fulltypename$(typ$) + ") not defined": GOTO errmes
'create variable
IF LEN(s$) THEN typ$ = s$ ELSE typ$ = t$
IF optionexplicit THEN a$ = "Variable '" + n$ + "' (" + symbol2fulltypename$(typ$) + ") not defined": GOTO errmes
bypassNextVariable = -1
retval = dim2(n$, typ$, method, "")
IF Error_Happened THEN GOTO errmes
'note: variable created!
Taking a moment to dig into the source, it appears as if this behavior is intentional.
On the other hand, once OPTION _EXPLICIT has done it's job, it can be commented out before the run.I don't agree because
using OPTION _EXPLICIT forces you to DIM a hell of allot more things (everything) but that in turn forces you to think allot more about types the variable may declared.I think that stopping the compilation this OPTION _EXPLICIT works with a Pascal spirit and not with a BASIC spirit.
IncreaseT
PrintT
END
SUB IncreaseT
SHARED t AS INTEGER
t = t +1
END SUB
SUB PrintT
SHARED t AS INTEGER
PRINT t
END SUB
t = 0
IncreaseT
PrintT
END
SUB IncreaseT
SHARED t AS INTEGER
t = t +1
END SUB
SUB PrintT
SHARED t AS INTEGER
PRINT t
END SUB