GLBasic forum

Feature request => IDE/Syntax => Topic started by: Moebius on 2011-Jan-14

Title: Global variables in INLINE?
Post by: Moebius on 2011-Jan-14
Would it be possible to allow INLINE code to declare global variables?  It would be good if having "GLOBAL int myvar;" would cause GLB to move the declaration outside of any functions, allowing us to declare global variables of any type in inline code.  Is this okay to implement?
Title: Re: Global variables in INLINE?
Post by: Kitty Hello on 2011-Jan-14
No. If you want an inline global, define it outside a function, or use GLOBAL for float/int.
Title: Re: Global variables in INLINE?
Post by: Moebius on 2011-Jan-14
Defining vars in inline outside functions and subs doesn't seem to make it global...  Isn't the main GLB program inside a C++ func.?  If so it's physically impossible to define vars outside of any function...
Anyway this should compile if INLINE vars outside of functions in GLB are global:
Code (glbasic) Select
INLINE
DGInt MyVar = 5;
ENDINLINE
GOSUB MySub

SUB MySub:
LOCAL GLVar#
INLINE
GLVar = MyVar; //error - MyVar not declared in this scope...
ENDINLINE
PRINT GLVar, 10, 10;
SHOWSCREEN
KEYWAIT
END
ENDSUB

The compiler reports that 'MyVar' was not declared in the scope of the sub.  If it was globalled this shouldn't happen...

It's not a big deal but it would be nice to have this extra functionality if it isn't too hard to implement, and won't allow us to mess up GLBasic's internal workings...
Title: Re: Global variables in INLINE?
Post by: Kitty Hello on 2011-Jan-16
it's in "main()" now - you must end main with a dummy function, or a new gbas file.
Title: Re: Global variables in INLINE?
Post by: Moebius on 2011-Jan-17
Oh I get it now!  Thanks!
This works:
Code (glbasic) Select
foo()
foo2()

FUNCTION dummy:
ENDFUNCTION

INLINE
DGInt myvar;
ENDINLINE

FUNCTION foo:
INLINE
myvar = 0.5;
ENDINLINE
ENDFUNCTION

FUNCTION foo2:
LOCAL GLVar
INLINE
GLVar = myvar;
ENDINLINE
PRINT GLVar, 10, 10
SHOWSCREEN
KEYWAIT
END
ENDFUNCTION