'Shared Dim' not allowed!

Just starting out? Need help? Post your questions and find answers here.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

'Shared Dim' not allowed!

Post by Psychophanta »

Inside a 'Procedure' we can define "Static" or "Protected" arrays, but we can not define a "Shared" one.
Is it due to avoid problems for the global? Then, why is there allowed to define an array as "Global" inside a procedure?
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Axolotl
Addict
Addict
Posts: 872
Joined: Wed Dec 31, 2008 3:36 pm

Re: 'Shared Dim' not allowed!

Post by Axolotl »

I cannot see the problem?
Globals, Static and Shared arrays are working inside a procedure here.

Code: Select all

Global Dim g_Numbers(0) 
Dim sg_Numbers(0)   ; <-- this is needed for shared inside procedures. 

Procedure Main()
  Static Dim s_Numbers(0) 
  Shared sg_Numbers() 

  Dim g_Numbers(4) 
  Dim s_Numbers(4) 
  Dim sg_Numbers(4) 
  
  For i = 0 To 4
    g_Numbers(i)  = i 
    s_Numbers(i)  = i 
    sg_Numbers(i) = i 
  Next i 

  ReDim g_Numbers(8) 
  ReDim s_Numbers(8) 
  ReDim sg_Numbers(8) 

  For i = 5 To 8
    g_Numbers(i)  = i 
    s_Numbers(i)  = i 
    sg_Numbers(i) = i 
  Next i 


  For i = 0 To 8
    Debug "Global " + g_Numbers(i) 
    Debug "Static " + s_Numbers(i) 
    Debug "Shared " + sg_Numbers(i) 
  Next i 

EndProcedure 

End Main() 
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: 'Shared Dim' not allowed!

Post by Psychophanta »

Please read again :wink:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
miso
Enthusiast
Enthusiast
Posts: 491
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: 'Shared Dim' not allowed!

Post by miso »

@Psychophanta
Could you post a short example that points out the problem?
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: 'Shared Dim' not allowed!

Post by Psychophanta »

miso wrote: Fri Dec 06, 2024 6:29 pm @Psychophanta
Could you post a short example that points out the problem?
:shock: :x

Code: Select all

Procedure Main()
  Shared Dim s_Numbers(0)
EndProcedure
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
STARGÅTE
Addict
Addict
Posts: 2259
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: 'Shared Dim' not allowed!

Post by STARGÅTE »

The "Shared" keyword requires a valid definition in the main code. You just share the scope of the definition.
"Static" and "Protected" are definitions.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
miso
Enthusiast
Enthusiast
Posts: 491
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: 'Shared Dim' not allowed!

Post by miso »

You can't share something that not exists... Share something that exists but is outside the scope of your procedure.
Axolotl
Addict
Addict
Posts: 872
Joined: Wed Dec 31, 2008 3:36 pm

Re: 'Shared Dim' not allowed!

Post by Axolotl »

I read your post and my example shows a working code. See the line with the comment. :!:
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: 'Shared Dim' not allowed!

Post by Psychophanta »

@STARGÅTE
"Global" keyword does not require a valid def in the main, why does "Share" require it?

@miso
"Global" keyword does not require a valid def in the main (is able to share something that not exists), why does "Share" require it?

@Axolotl
Done. I watched your post carefully, so please do you the same. Your post is not in the point of the thread.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Fred
Administrator
Administrator
Posts: 18350
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: 'Shared Dim' not allowed!

Post by Fred »

You can't share something which is not declared. 'Shared' doesn't declare anything, it allows its use in the function for something which is not globally defined. It completely different than Global, so I don't know why you want to compare both...
Olli
Addict
Addict
Posts: 1264
Joined: Wed May 27, 2020 12:26 pm

Re: 'Shared Dim' not allowed!

Post by Olli »

@psychophanta

An array :

Code: Select all

Structure myArray
 Array i.i(1023)
EndStructure
An creation :

Code: Select all

Define *this.myArray = AllocateMemory(SizeOf(myArray) )
InitializeStructure(*this, myArray)
In a procedure :

Code: Select all

Shared *this
Right ?
User avatar
mk-soft
Always Here
Always Here
Posts: 6320
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: 'Shared Dim' not allowed!

Post by mk-soft »

You can't confuse beginners any more than that.

Please also simply publish examples
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Olli
Addict
Addict
Posts: 1264
Joined: Wed May 27, 2020 12:26 pm

Re: 'Shared Dim' not allowed!

Post by Olli »

I aborted 'shared' use, since many years. I think that, if we must find the origin of a nightmare in which we are searching why a variable has a wrong value, I think that shared should be the last thing where we bring ours eyes in a source code.
I lost time with bugs hidden by shared.

It is a little bit as adding a light switch in the home, by searching the first wire which was near.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: 'Shared Dim' not allowed!

Post by Psychophanta »

@Fred

I know, it is no much to do with 'Global', however:
We can see 'Shared" does declare variables inside a Procedure for be valid outside it (everytime we do not use 'EnableExplicit' previously):

Code: Select all

Procedure hg()
  Shared var.f
  var=3.33
EndProcedure
hg()
debug var
ANOTHER thing is that it can not declare arrays, maps, lists, etc.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
miso
Enthusiast
Enthusiast
Posts: 491
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: 'Shared Dim' not allowed!

Post by miso »

ANOTHER thing is that it can not declare arrays, maps, lists, etc.
It also can't define variables. Without enable explicit, variables defines itself, so you don't have to.
Please, don't be mad at me, but I'm confused, I don't see anymore what's the the goal in this thread. I'm out.
Post Reply