Namespace junk
Const maxpt = 100
const maxarray = 10
Type _Array
x(maxpt) as single
y(maxpt) as single
end type
Dim Shared MyArray as _Array Ptr
MyArray = CALLocate (MaxArray*len(MyArray))
END Namespace
Namespace junk
Const maxpt = 100
const maxarray = 10
Type _Array
x(maxpt) as single
y(maxpt) as single
end type
END Namespace
Dim Shared MyArray as _Array Ptr
MyArray = CALLocate (MaxArray*len(MyArray))
If it's illegal to assign a variable within a Namespace block definition, then why?
Namespaces aren't allowed to contain code directly, only inside procedures declared in that namespace. That's because a namespace isn't a scope, it's not something that is executed, it's just something that can be used to hold declarations.
Sure enough an assignment is code that needs to be executed. If written at the toplevel, outside the namespace, it becomes part of the implicit main() procedure (which is one of FB's quirky specialties). Note that global constructors are executed before the main() procedure, so code in such constructors may find that global variables aren't set up yet if that setup is done through code in main().
Any variable declared in namespace is implicitely static and visible throughout the entire program ('Shared' is useless). Therefore only an initializer with a constant is authorized:
Namespace junk
Const maxpt = 100
const maxarray = 10
Type _Array
x(maxpt) as single
y(maxpt) as single
end type
END Namespace
Dim Shared MyArray as junk._Array Ptr
MyArray = CALLocate (junk.MaxArray*len(MyArray))
Namespace junk
Const maxpt = 100
const maxarray = 10
Type _Array
x(maxpt) as single
y(maxpt) as single
end type
Dim MyArray as _Array ptr
END Namespace
Junk.MyArray = CALLocate (junk.MaxArray*len(Junk._Array))
With Junk.MyArray[0]
.x(0) = 1
.y(0) = 10
print .x(0) & "," & .y(0)
end with
sleep
Namespace junk
Const maxpt = 100
const maxarray = 10
Type _Array
x(maxpt) as single
y(maxpt) as single
end type
Dim MyArray as _Array ptr
END Namespace
Junk.MyArray = CALLocate (junk.MaxArray*len(Junk._Array))
With Junk.MyArray[0]
.x(0) = 1
.y(0) = 10
print .x(0) & "," & .y(0)
end with
print MyArray[0].x(0) 'THIS LINE CAUSES an ERROR, Variable MyArray not declared
sleep
Yes, I agree with you. junk.MyArray is global (static and shared) in this example
The point I was trying to verify is that the variable name MyArray is local to the JUNK namespace. MyArray is not declared outside JUNK and therefore is not encroaching on a possible conflict with another variable in MAIN() that might be declared as MyArray.
I'm making a library, and I don't want to begin using up variable names that might cause a conflict when linked to some other program.