'Shared Dim' not allowed!
- Psychophanta
- Always Here

- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
'Shared Dim' not allowed!
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?
Is it due to avoid problems for the global? Then, why is there allowed to define an array as "Global" inside a procedure?
Re: 'Shared Dim' not allowed!
I cannot see the problem?
Globals, Static and Shared arrays are working inside a procedure here.
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).
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).
- Psychophanta
- Always Here

- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
Re: 'Shared Dim' not allowed!
Please read again 
Re: 'Shared Dim' not allowed!
@Psychophanta
Could you post a short example that points out the problem?
Could you post a short example that points out the problem?
- Psychophanta
- Always Here

- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
Re: 'Shared Dim' not allowed!
miso wrote: Fri Dec 06, 2024 6:29 pm @Psychophanta
Could you post a short example that points out the problem?
Code: Select all
Procedure Main()
Shared Dim s_Numbers(0)
EndProcedure
Re: 'Shared Dim' not allowed!
The "Shared" keyword requires a valid definition in the main code. You just share the scope of the definition.
"Static" and "Protected" are definitions.
"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 more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Re: 'Shared Dim' not allowed!
You can't share something that not exists... Share something that exists but is outside the scope of your procedure.
Re: 'Shared Dim' not allowed!
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).
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).
- Psychophanta
- Always Here

- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
Re: 'Shared Dim' not allowed!
@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.
"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.
Re: 'Shared Dim' not allowed!
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...
Re: 'Shared Dim' not allowed!
@psychophanta
An array :An creation :In a procedure :Right ?
An array :
Code: Select all
Structure myArray
Array i.i(1023)
EndStructureCode: Select all
Define *this.myArray = AllocateMemory(SizeOf(myArray) )
InitializeStructure(*this, myArray)Code: Select all
Shared *thisRe: 'Shared Dim' not allowed!
You can't confuse beginners any more than that.
Please also simply publish examples
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
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: 'Shared Dim' not allowed!
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.
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.
- Psychophanta
- Always Here

- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
Re: 'Shared Dim' not allowed!
@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):
ANOTHER thing is that it can not declare arrays, maps, lists, etc.
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
Re: 'Shared Dim' not allowed!
It also can't define variables. Without enable explicit, variables defines itself, so you don't have to.ANOTHER thing is that it can not declare arrays, maps, lists, etc.
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.


