idle wrote: Fri Oct 11, 2024 9:15 pmThere is no difference between global or shared.
This is clearly not true. The
GLOBAL directive would render access to the so-defined variable
globally throughout the program, whereas the
SHARED directive merely
shares the variable-scope with the selected procedure, remaining inaccessible to other procedures that have not shared its scope.
The inline assembly code in your example is simply operating on the variable in the main scope, and not on the procedural stack.
Code: Select all
Procedure foo()
Protected x = 456
!MOV qword [v_x], 123
Debug x ;outputs 456
EndProcedure
foo()
Debug x ;outputs 123
idle wrote: Fri Oct 11, 2024 9:15 pmThe benefit of shared is that the IDE will give you a warning if the shared variable isn't declared globally.
This is also not true. In PureBasic, when the
SHARED directive is applied to any variable,
even if it has not been defined, that variable will automatically be defined for the main scope by default, without any errors or warnings.
Code: Select all
Procedure foo()
Shared x
x = 123
EndProcedure
foo()
Debug x ;outputs 123
This is barring the use of the
EnableExplicit directive, of course.