Page 1 of 2
'Shared Dim' not allowed!
Posted: Fri Dec 06, 2024 2:39 pm
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?
Re: 'Shared Dim' not allowed!
Posted: Fri Dec 06, 2024 5:23 pm
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()
Re: 'Shared Dim' not allowed!
Posted: Fri Dec 06, 2024 6:04 pm
by Psychophanta
Please read again

Re: 'Shared Dim' not allowed!
Posted: Fri Dec 06, 2024 6:29 pm
by miso
@Psychophanta
Could you post a short example that points out the problem?
Re: 'Shared Dim' not allowed!
Posted: Fri Dec 06, 2024 7:03 pm
by Psychophanta
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!
Posted: Fri Dec 06, 2024 7:08 pm
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.
Re: 'Shared Dim' not allowed!
Posted: Fri Dec 06, 2024 7:40 pm
by miso
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!
Posted: Sat Dec 07, 2024 12:13 am
by Axolotl
I read your post and my example shows a working code. See the line with the comment.

Re: 'Shared Dim' not allowed!
Posted: Sat Dec 07, 2024 5:16 pm
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.
Re: 'Shared Dim' not allowed!
Posted: Sat Dec 07, 2024 5:45 pm
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...
Re: 'Shared Dim' not allowed!
Posted: Sat Dec 07, 2024 10:56 pm
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 :
Right ?
Re: 'Shared Dim' not allowed!
Posted: Sat Dec 07, 2024 11:06 pm
by mk-soft
You can't confuse beginners any more than that.
Please also simply publish examples
Re: 'Shared Dim' not allowed!
Posted: Sun Dec 08, 2024 6:27 am
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.
Re: 'Shared Dim' not allowed!
Posted: Sun Dec 08, 2024 9:07 am
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.
Re: 'Shared Dim' not allowed!
Posted: Sun Dec 08, 2024 10:06 am
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.