[4.02]EnableExplicit and Shared

Everything else that doesn't fall into one of the other PB categories.
User avatar
HeX0R
Addict
Addict
Posts: 1220
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

[4.02]EnableExplicit and Shared

Post by HeX0R »

I'm getting an error message Test wouldn't be declared:

Code: Select all

EnableExplicit

Procedure Dummy()
	Shared Test.POINT
	
EndProcedure
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

yes i can confirm this.

this works :

Code: Select all

EnableExplicit

Define Test.POINT

Procedure Dummy()
   Shared Test
   Debug Test\x
   Debug Test\y
EndProcedure 

Dummy()
Does this means that 'Shared' var should be defined once outside the procedure ? If so, maybe it's not a bug (?)
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
jear
User
User
Posts: 20
Joined: Sun Dec 28, 2003 12:27 am
Location: Ammerland

Post by jear »

But this doesn't work.
So we are not able to share variables between procedures, without declaring it in the main program too.

Code: Select all

EnableExplicit 

Procedure Dummy_1() 
  Shared Test.POINT 
  
EndProcedure 

Procedure Dummy_2() 
  Shared Test.POINT 
  
EndProcedure 

Dummy_1()
Dummy_2()
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

This was changed to have a consistent behaviour with shared LinkedLists and Arrays,
where they need to be defined in the main source first as well.
quidquid Latine dictum sit altum videtur
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

ok freak,

so, is this the good/clean syntax ?

Code: Select all

EnableExplicit

Define myPoint.POINT

Procedure Dummy1()
  Shared myPoint
  myPoint\x = 111
  myPoint\y = 222
EndProcedure

Procedure Dummy2()
  Shared myPoint
  Debug myPoint\x
  Debug myPoint\y
EndProcedure

Dummy1()
Dummy2()
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

Hmmmm, i'm just wondering...

And what the use to 'Shared' a variable previously defined as 'Global' ?
I think this should raise a debugger warning, no ?

Code: Select all

EnableExplicit

Global myPoint.POINT ; myPoint as 'Global'

Procedure Dummy1()
  Shared myPoint ; This line should be removed - and it should raise a warning ! (?)
  myPoint\x = 111
  myPoint\y = 222
EndProcedure

Procedure Dummy2()
  Debug myPoint\x
  Debug myPoint\y
EndProcedure

Dummy1()
Dummy2()
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

It's no use, but it's not an error as well..
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

months ago we discussed in the german forum, whether the implementation
of Shared is similar to the basic idea of Shared Variables or not.

since PureBasic has a MainCode, where you also declare Globals,
its not that strange that Shared variables are accessable in this Maincode, too.
and with this, its consistent, that it has to be Defined in the Maincode,
when EnableExplicit is active.

@flype
> what the use to 'Shared' a variable previously defined as 'Global' ?
the Variable is already Global, so it can be accessed in the Procedure.

if you try something like this:

Code: Select all

Global test.s
Define test.f
you'll receive an Error.

so, if you keep in mind, to preDefine every Shared Variable in the Maincode,
you will be informed if some name conflict appears.
oh... and have a nice day.
Post Reply