Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bestest non-bug yet!
#1
Code: (Select All)
OPTION _EXPLICIT
f 2

SUB f (x)
    DIM x AS LONG
    PRINT x
END SUB

Note that the above is perfectly valid.  In fact, Option _Explict won't even toss us an error saying "Undeclared Variable" here.  It passes the IDE inspection, compiles just peachy fine, and is about the best example of "How NOT to Program" that I can think of.

Why the heck does BASIC allow this type of junk to ever pass muster to even begin with?!

And it that doesn't boggle your brain any, take a look at the extended version of this mess:

Code: (Select All)
OPTION _EXPLICIT
f 2

SUB f (x)
    DIM x AS LONG
    PRINT x, x!
END SUB

At no point did we declare a variable as x!, yet parameter x defaults to SINGLE, so Option Explicit happily accepts it as being declared as SINGLE, which makes x! valid -- except we can't reference it as X as X is now a local LONG, which is not to be confused with parameterX, which is SINGLE and can be referenced by x! but not x......

Confused yet??
Reply
#2
It's too late to do anything about it and risk breaking a lot of programs. Especially those written by somebody who might still be modifying his stuff away from A, A!, A$, A&, A&& and many others...

I'm not sure but this might be because the QB64 code processor creates a ridiculous internal C++ variable name, which starts with the variable name in BASIC code, and then the type such as "SINGLE" or "STRING" or an UDT. So there are no doubts at C++ code-mess level about which one is A and which one is A$, without caring if `OPTION _EXPLICIT` is going on.

This is just an exerpt from random1's program modified by me to include some of Steve's code presented in another thread:
Code: (Select All)
*__DOUBLE_A=pow2(*__DOUBLE_A, 2 );
if(!qbevent)break;evnt(15);}while(r);
do{
qbs_set(__STRING_ANO,FUNC_N2S(qbs_ltrim(qbs_str((double)(*__DOUBLE_A)))));
qbs_cleanup(qbs_tmp_base,0);
if(!qbevent)break;evnt(17);}while(r);
do{
qbs_set(__STRING_ANO,func_mid(__STRING_ANO, 1 , 6 ,0|1));
qbs_cleanup(qbs_tmp_base,0);
if(!qbevent)break;evnt(18);}while(r);
do{
*__SINGLE_P=*__SINGLE_P+func_val(__STRING_ANO);
Reply




Users browsing this thread: 1 Guest(s)