(09-29-2023, 02:31 AM)SMcNeill Wrote:(09-28-2023, 07:16 PM)RhoSigma Wrote:(09-28-2023, 06:51 PM)SMcNeill Wrote: You guys make me cry, reusing A for both string and long in the same function.
I regularly have those duplicate/triple etc. uses in my programs, no problem as all generate different variables on the C/C++ side of things.
Code: (Select All)DIM a$, a%%, a~%%, a%, a~%, a&, a~&, a&&, a~&&, a!, a#, a##
turns into:
Code: (Select All)__STRING_A->len=0;
*__BYTE_A=0;
*__UBYTE_A=0;
*__INTEGER_A=0;
*__UINTEGER_A=0;
*__LONG_A=0;
*__ULONG_A=0;
*__INTEGER64_A=0;
*__UINTEGER64_A=0;
*__SINGLE_A=0;
*__DOUBLE_A=0;
*__FLOAT_A=0;
Here's why I'd never do this:
And the code of this abomination:
Code: (Select All)TYPE foo
foo AS STRING
END TYPE
DIM foo AS foo
INPUT "Give me an integer number =>"; foo&
foo$ = STR$(foo&)
foo.foo = LEFT$(foo$, 1)
GOSUB foo
PRINT "Foo"; foo.foo
END
foo:
foo% = ASC(foo.foo)
foo# = foo% + RND * 255
foo& = foo# MOD 256
foo$ = STR$(foo&)
foo&& = ASC(foo$) - RND * 256
foo~%% = foo&& MOD 256
foo.foo = CHR$(foo~%%)
RETURN
Now, I offer a cookie to the first person who can decipher what the heck is going on here, and explain WHY foo.foo is printing out its own "Foo" for us, when the last assigned command for it before the PRINT statement is a very simple:
foo.foo = CHR$(foo~%%)
Shouldn't this be a single ASCII character? What the heck is going on here? How'd we get this output? And could anyone trace this and debug it if there was 100 lines of other code involved here, doing other things in between this mess?
Well Steve, it's your way to turn a made statement into something completely different.
We originally were talking about SIMPLE variables, not about TYPEs, its elements or even program labels, those have their own different namespace.
The made statement was about same named SIMPLE VARIABLES, that's it.
But to answer your question, my guess is that the error already happens in the IDE/Compiler when the code is translated into C/C++. I've seen many places in the QB64pe.bas source which handles variable typing and never got a clue what's exactly done in there.
A computer NEVER does what we expect, it simply is doing what's PROGRAMMED.
GuiTools, Blankers & other Projects:
https://qb64phoenix.com/forum/forumdisplay.php?fid=32
Libraries & useful Functions:
https://qb64phoenix.com/forum/forumdisplay.php?fid=23
https://qb64phoenix.com/forum/forumdisplay.php?fid=32
Libraries & useful Functions:
https://qb64phoenix.com/forum/forumdisplay.php?fid=23