Oxygen Basic
Information => Open Forum => Topic started by: JRS on January 20, 2013, 10:50:37 PM
-
I know in my PowerBASIC coding I frequently rely on the compiler initializing a local to zero. Only by looking close at a number of programming statements in the body of the procedure on a case by case basis would it be possible to determine whether it was/is necessary or not.
SUB test
LOCAL a
PRINT a,"\n"
END SUB
test
jrs@laptop:~/sb/test$ scriba iszero.sb
undef
jrs@laptop:~/sb/test$
@Charles - How does OxygenBasic handle local variable initialization. Is PowerBASIC unique in how it handles local variables?
-
This is the way how works..easy..right?
SUB test
INT a
a=5
PRINT str(a)
END SUB
test()
-
In the Basic tradition, Oxygen initialises all variables (including arrays) to null.
This can be overridden for local variables in a procedure but it is seldom needed.
Oxygen also delivers clean memory blocks, even at low level:
sys a=getmemory 0x1000
a now points to a block of 4096 null bytes.
-
Ed,
You did have the right idea but instead of b= 0 if I use braces as in int b={0}; I can use it for all data types. I implemented it but need to do a lot more testing. Thanks for the idea.
James
I agree with how Charles is initializing data and structures. What is wrong with using NULL? bc9 is a C translator and that is how C initialize its data and structures from what I understand.
a = NULL
a$ = NULL
a[NULL]
a = MyFunction(arg1,arg2,NULL)
In ScriptBasic the undef serves the same purpose as NULL.
-
In Oxygen, initialisation of local variables to null is the normal rule but it is possible to override it.
function f()
#noinit
sys a
print a
end function
f 'result: '1572416 etc
However this will never work for strings. They are always set to null
Another way to bypass null initialisation is using implicit dim, (a bit like scriptbasic):
va=123 'va is automatically created as sys
vb=42.5 'vb is automatically created as double float
Charles
-
Another way to bypass null initialisation is using implicit dim, (a bit like scriptbasic):
implicit dim - I like that term better then smart vars. :D