Qbasicnews.com
October 14, 2019, 09:45:05 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Interesting problem with COMMON/DIM SHARED  (Read 5016 times)
subxero
Member
*
Posts: 78



WWW
« on: January 31, 2005, 09:25:44 AM »

First of all, FB 0.11 rules big-time, except for this bug I seem to have come across (please tell me I'm doing something wrong, so I don't have to wait for 0.12 :-P)

I have these lines in my main include file (used by every module):

Code:
COMMON SHARED Layers() AS SDL_Surface POINTER
DIM SHARED Layers(1 TO 5) AS SDL_Surface POINTER


That compiles successfully, but any reference to the array at all crashes the program.

So I tried putting the dimensions in the COMMON...

Code:
COMMON SHARED Layers(1 TO 5) AS SDL_Surface POINTER
DIM SHARED Layers(1 TO 5) AS SDL_Surface POINTER


Also compiles fine, but crashes on any reference to Layers().

Lastly, just as a test, regardless of whether or not the array would be common, I tried:

Code:
DIM SHARED Layers(1 TO 5) AS SDL_Surface POINTER


This code worked fine when Layers() was referenced in engine.bas, my main module, but crashed when it was referenced in sdlwrap.bas, my graphics module. When I say "referenced," I mean used generally - I check the contents of Layers( ) with a PRINT statement as a sort of debugging, and the PRINT executes about halfway and crashes.

Tell me I'm doing something wrong. I'd love to continue programming. :-)

As a side note: it seems that if the array is dynamic, everything works fine - as is with my MainFont() array, my Tileset() array, and my Level() array.
Logged

color=blue]subxero - admin at this place.[/color]
Antoni Gual
Na_th_an
*****
Posts: 1434



WWW
« Reply #1 on: January 31, 2005, 09:43:43 AM »

FB'S COMMON supports only dynamic arrays.
I read it, can't remember where...
Fortunately differnt people remenbers different parts of the specs, and all togheter make a complete manual. Recalls me Fahrenheit 451 Cheesy
Logged

Antoni
steven_basic
Senior Member
**
Posts: 244


WWW
« Reply #2 on: January 31, 2005, 11:13:48 AM »

Quote from: "Antoni Gual"
Fortunately differnt people remenbers different parts of the specs, and all togheter make a complete manual. Recalls me Fahrenheit 451


* Applause *

Any Bradbury references so expertly inserted into the conversations deserve admiration.
Logged

ature has its way of warning a person away from danger:  The distinct black and white coloration on a skunk, the chilling buzz of a rattlesanke, a redneck handing you his beer and saying "Watch this!"
1000101
Ancient Guru
****
Posts: 519



WWW
« Reply #3 on: January 31, 2005, 11:31:55 AM »

Quote from: "steven_basic"
Any Bradbury references so expertly inserted into the conversations deserve admiration.


It would if Ray Bradbury didn't totally suck.

subxero:  Common sucks and is bad programming habit.  You should pass the list of surfaces as a parameter instead of referencing them as an external list.
Logged

Life is like a box of chocolates', hrm, WTF, no it isn't, more like, 'life is like a steaming pile of horse crap.'
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #4 on: January 31, 2005, 11:54:54 AM »

Quote from: "1000101"
subxero:  Common sucks and is bad programming habit.  You should pass the list of surfaces as a parameter instead of referencing them as an external list.


Agreed 1000^1000%.
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Z!re
*/-\*
*****
Posts: 4599


« Reply #5 on: January 31, 2005, 12:10:22 PM »

Yaya, and GOTO is bad.. yadda yadda..


Not everyone knows how to do fancy pointers and stuff..
We use what we've always used, and it works :lol:

Atleast I do..



And btw, did you know, in fb < 0.11, you could use redim on static arrays... weird...
Logged
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #6 on: January 31, 2005, 12:14:59 PM »

No pointers, just extra parameters. That way it's easier to get track of your data. At least for me. I don't like having a bunch of inter-module globals. You end not knowing where the data belongs to.
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Z!re
*/-\*
*****
Posts: 4599


« Reply #7 on: January 31, 2005, 01:00:26 PM »

Oh.. you mean like
Code:
MySub arg1, arg2, array()


Sry, my bad, thought you meant some fancy pointer thingy stuff blarg Cheesy
Logged
TheBigBasicQ
*/-\*
*****
Posts: 4550



WWW
« Reply #8 on: January 31, 2005, 01:10:34 PM »

Quote from: "na_th_an"
Quote from: "1000101"
subxero:  Common sucks and is bad programming habit.  You should pass the list of surfaces as a parameter instead of referencing them as an external list.


Agreed 1000^1000%.

For once I agree with you. COMMONs, GOTOs should never be used! Unless absolutely essential :roll:
Logged
Sterling Christensen
Na_th_an
*****
Posts: 1328


« Reply #9 on: January 31, 2005, 02:36:41 PM »

The COMMON can be in the include file, but the DIM SHARED shouldn't be. The variable should be DIMmed only in one module.

Like so:
Quote from: "main.bas"
DECLARE SUB printBlah
COMMON SHARED blah
DIM SHARED blah

blah = 2
printBlah
END

Quote from: "module2.bas"
DECLARE SUB printBlah
COMMON SHARED blah

SUB printBlah
PRINT blah
END SUB
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!