Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unhandled Error Bug Fixed
#1
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
Reply
#2
(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?
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#3
[Image: image.png]

What am I missing here? This seems to be what you reported, and I'm not getting any errors from this.
Reply
#4
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.
Reply
#5
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
Reply
#6
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.
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#7
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
Reply
#8
(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.
Reply
#9
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)
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#10
Note to self: Don't copy/paste into a code box without clicking "Remove Formatting"...LOL
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is this a bug with Round or is it just me BarrySWTP 10 1,244 07-07-2025, 08:40 PM
Last Post: BarrySWTP
  Exiting FOR NEXT, maybe a bug? Version 4.1.0 on Linux Circlotron 4 841 05-09-2025, 02:22 AM
Last Post: Circlotron
  Compile error when .bas name is same as a directory (linux) Dav 3 771 10-18-2024, 03:32 PM
Last Post: Kernelpanic
  I have fallen in a bug or weird behaviour TempodiBasic 2 667 10-08-2024, 06:09 PM
Last Post: TempodiBasic
  Error Message bplus 3 887 08-20-2024, 09:03 PM
Last Post: Pete

Forum Jump:


Users browsing this thread: 1 Guest(s)