Posts: 98
Threads: 24
Joined: Apr 2022
Reputation:
6
05-17-2022, 11:22 AM
(This post was last modified: 05-17-2022, 06:15 PM by TarotRedhand.)
Bug Report.
At the top of my code I have the '$DYNAMIC switch.
I have a sub that takes an array as a parameter.
In that sub I REDIM that array.
The code compiles fine.
When run the compiled code I receive an Unhandled Error message for a Duplicate Definition on the line where I REDIM the array. It asks if I want to continue Yes/No. This shouldn't happen. It is a bug with the current version of QB64. It didn't happen in QB4.5.
TR
Posts: 3,967
Threads: 177
Joined: Apr 2022
Reputation:
219
05-17-2022, 04:05 PM
(This post was last modified: 05-17-2022, 04:08 PM by bplus.)
(05-17-2022, 11:22 AM)TarotRedhand Wrote: Bug Report.
At the top of my code I have the '$DYNAMIC switch.
I have a sub that takes an array as a parameter.
In that sub I REDIM that array.
The code compiles fine.
When run the compiled code I receive an Unhandled Error message for a Duplicate Definition on the line where I REDIM the array. It asks if I want to continue Yes/No. This shouldn't happen. It is a bug with the current version of QB64. It didn't happen in QB4.5.
TR
Did you originally use REDIM for the array and are you REDIM with same type and dimensions?
Wait...
I don't use '$DYNAMIC switch because STATIC arrays have their place too, often in same code app.
Does '$DYNAMIC switch apply to library code? Does it go in .BI too? That's when the problem popped up, when you were trying Matrix library, I recall seeing.
Maybe with the switch you shouldn't use REDIM?
b = b + ...
Posts: 2,696
Threads: 327
Joined: Apr 2022
Reputation:
217
What am I missing here? This seems to be what you reported, and I'm not getting any errors from this.
Posts: 2,696
Threads: 327
Joined: Apr 2022
Reputation:
217
Code: (Select All) '$dynamic
foo b(), 100
Print UBound(b)
Sub foo (A(), limit)
Dim A(limit)
End Sub
Is this what the code looks like? Like this, I can reproduce the results you mention, but it's not a bug. It's literally what it says it is: A duplicate definition.
SUB foo (A() <-- here we define the dynamic array A().
DIM A(limit) <-- and here we try to define the dynamic array A().
If that dim becomes a REDIM, everything works as expected for me.
Unless I'm missing something here.
Posts: 98
Threads: 24
Joined: Apr 2022
Reputation:
6
05-17-2022, 06:24 PM
(This post was last modified: 05-17-2022, 06:40 PM by TarotRedhand.)
It' OK guys, I found a fix for this. It was how QB64 handles libraries. At the top of the BM file, I had the '$DYNAMIC switch but not in the program that called a SUB in that library. I had expected that because the '$DYNAMIC switch occurred before the SUB in the library that it would cover the use of it in that program. It appears that isn't the way QB64 works. Then I had an idea that I thought sounded a little crazy. I created a BI file into which I moved the '$DYNAMIC switch and removed it from the BI file. I then put a '$INCLUDE: into the small program. Slightly, to my surprise it worked.
Thanks guys.
TR
Posts: 3,967
Threads: 177
Joined: Apr 2022
Reputation:
219
That brings up a question, do commands to compiler work in BI's? Looks like they don't. I don't expect the compiler to work with one set in main Module and another set in BI files.
If library code is expecting arrays to behave Dynamically it should at least be noted with word of warning in the .BI code and even the routines in the BM file.
b = b + ...
Posts: 98
Threads: 24
Joined: Apr 2022
Reputation:
6
It would seem that they do. I just edited the calling program to force a REDIM necessary and it worked flawlessly. No error messages. FWIW, I have updated the matrices thread to reflect this. The small program is in my most recent program there.
TR
Posts: 2,696
Threads: 327
Joined: Apr 2022
Reputation:
217
(05-17-2022, 06:35 PM)bplus Wrote: That brings up a question, do commands to compiler work in BI's? Looks like they don't. I don't expect the compiler to work with one set in main Module and another set in BI files.
If library code is expecting arrays to behave Dynamically it should at least be noted with word of warning in the .BI code and even the routines in the BM file.
Commands work in BI and BM files. Basically all we do with an include is basically a copy paste of the code that you include, into the point where you include it.
So let's say I have a file "HW.BI" which is nothing more than PRINT "Hello World"...
I write a program with that file, like so:
Code: (Select All) '$INCLUDE:'HW.BI'
DO
LOOP UNTIL _KEYHIT
[font=Monaco, Consolas, Courier, monospace]'$INCLUDE:'HW.BI'[/font]
This code is literally nothing more than:
Code: (Select All) PRINT "Hello World"
[font=Monaco, Consolas, Courier, monospace]DO[/font]
[font=Monaco, Consolas, Courier, monospace]LOOP UNTIL _KEYHIT[/font]
[font=Monaco, Consolas, Courier, monospace][/font]
[align=left][font=Monaco, Consolas, Courier, monospace][font=Monaco, Consolas, Courier, monospace]PRINT "Hello World"[/font][/font][/align]
So if you have a DEFINT or _DEFINE in your code, that _DEFINE only starts at the point where you include it. Everything before that is unaffected by it, but everything after it will be under its directive.
Posts: 3,967
Threads: 177
Joined: Apr 2022
Reputation:
219
OK so TR must have DIM'd his array before the compiler read the '$DYNAMIC in the Matrix BI?
I don't know, he's got it fixed now ;-))
Currently flawless with:
Code: (Select All) '$INCLUDE: 'MATRIX.BI'
Dim Sales!(3, 4), Prices!(4, 2), Result!(3, 2)
b = b + ...
Posts: 2,696
Threads: 327
Joined: Apr 2022
Reputation:
217
Note to self: Don't copy/paste into a code box without clicking "Remove Formatting"...LOL
|