Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Bug Reports / DBP - Weird Compilation Error - Bug?

Author
Message
Chris66
14
Years of Service
User Offline
Joined: 12th Aug 2009
Location:
Posted: 10th Dec 2010 16:28 Edited at: 11th Dec 2010 00:22
Hi there,

I'am using DBP 7.5

Compiling the code below send back this error :
Quote: "Cannot declare 'BYTE' twice ar line 96"





And compiling these ones (slightly modifications) works perfectly...




The code below works too.




And this latest one works fine too.




I would like to understand if I made a mistake into the 1st version of the code (using ':'?) or if the error is related to a bug of the compiler.

Thanks.

Cheers,
Chris
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 10th Dec 2010 18:45
Quote: " or if the error is related to a bug of the compiler"


Looks like it. I can confirm the symptoms you describe - but I'm not convinced any version works the way you expect. If I recall correctly conditional compilation code sometimes compiles and sometimes doesn't. I forget the details.

You'll have to wait for IanM to look at this.
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 10th Dec 2010 23:44
That's not conditional compilation - therr's a runtime conditional in there though.

Basically, none of that code should compile. You shouldn't be able to DIM an array to multiple types - DBPro uses static typing, which basically means that all types are fixed at compile time, and in each of those pieces of code, it's being told that the array has two different types.

So yes there's a bug, but it's not the bug you think it is.

In the meantime, pick a type that covers both number ranges (basically, it's WORD), and DIM the array once.

One the other subject, conditional compilation can be done in DBPro, but not with the standard IF statement - you have to play some pretty unreadable tricks with the #CONSTANT keyword.

Chris66
14
Years of Service
User Offline
Joined: 12th Aug 2009
Location:
Posted: 11th Dec 2010 00:21 Edited at: 11th Dec 2010 00:25
Hi,

Quote: "That's not conditional compilation - therr's a runtime conditional in there though."


Yes, Indeed.


Quote: "DBPro uses static typing, which basically means that all types are fixed at compile time..."


It's an important information I didn't know, thanks!


Quote: "So yes there's a bug, but it's not the bug you think it is."


Well my problem was with the weird compilation behaviour related to the place of the commands, not with the error I made using the Dim instruction... as I didn't know there was an error at this point : call me jar jar binks.


Quote: "In the meantime, pick a type that covers both number ranges (basically, it's WORD), and DIM the array once."


It looks like to be the easier way, thanks again.


Cheers,
Chris
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 11th Dec 2010 00:35
Quote: "That's not conditional compilation - therr's a runtime conditional in there though."


Oops - not quite what I meant to say, "conditional runtime declaration" would be closer to what I meant.

Quote: "One the other subject, conditional compilation can be done in DBPro, but not with the standard IF statement - you have to play some pretty unreadable tricks with the #CONSTANT keyword."


Sounds like something best avoided.
Chris66
14
Years of Service
User Offline
Joined: 12th Aug 2009
Location:
Posted: 11th Dec 2010 01:27 Edited at: 11th Dec 2010 12:15
Hi again,

A precision to avoid confusion and misunderstood :

Quote: "Basically, none of that code should compile. You shouldn't be able to DIM an array to multiple types "


In fact, in the code I provided in the 1st post the 2 variables Map_W & Map_Y are the same type which is WORD (sorry I didn't give that precision).
So, what I'am trying to do with this code is to declare a 2 dimentional array using variables.

Here is a more complete version of the previous code :







BTW


Just to be sure that I've understood how to use the DIM command correctly...

Please, can you tell me if this piece of code is correct ?




Thanks in advance!

Cheers,
Chris
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 11th Dec 2010 12:13
That's fine, but you are making work for yourself, having to write the same code once for each array. My advice is to use a single WORD array for both BYTE and WORD data.

Chris66
14
Years of Service
User Offline
Joined: 12th Aug 2009
Location:
Posted: 11th Dec 2010 12:49 Edited at: 11th Dec 2010 12:58
Thank you very much IanM!

Quote: "That's fine, but you are making work for yourself, having to write the same code once for each array. My advice is to use a single WORD array for both BYTE and WORD data."


You are right, this is not a good approach I made. So I modified the code this way using your advice :


I assume this is a wrong way to do (because I'am using a same array name in both DIM lines?)... but I definitely like this would be possible :




The right way should be this one :




Cheers
Chris
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 16th Dec 2010 17:27
Also,
Quote: "Global Dim ..."


You don't need go global dim variables. Dimmed variables are global anyway, even ones declared inside functions.

My signature is NOT a moderator plaything! Stop changing it!
Chris66
14
Years of Service
User Offline
Joined: 12th Aug 2009
Location:
Posted: 17th Dec 2010 11:09 Edited at: 22nd Dec 2010 01:25
Thanks Mobiius, so it seems I misunderstood what's explained into the "Data Types, Variables and Arrays" chapter of the help file.

Edit :

I made some tests and Local Dim declaration works fine when they are used into functions.

But indeed a Dim declaration made into the Main code (before "End") doesn't need to be declared as "Global".





Cheers,

Chris

Login to post a reply

Server time is: 2024-04-20 14:03:42
Your offset time is: 2024-04-20 14:03:42