[Implemented] Initial value for static variables

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

Post by Froggerprogger »

Yes, I haven't thought deep enough about it's consequences.
Now I agree, static initialization should be possible for constants only.

But - as already summarized by blueznl - for global and protected should any assignment (procedurereturn/vars) work - at the time of calling. Or does anybody see a problem there, too ?
%1>>1+1*1/1-1!1|1&1<<$1=1
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post by tinman »

Froggerprogger wrote:Yes, I haven't thought deep enough about it's consequences.
Now I agree, static initialization should be possible for constants only.
I don't see that it's a problem. Why can't the compiler be smart enough to detect whether the initialisation is constant only or dynamic and create the appropriate code?

Sure it's more work for Fred but isn't that what this forum is all about ;)
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

it could, but would more code as the check has to be done every call to the procedure, while a one time initalisation would only fill it up once, see? :-)

also, there's no need to check if the var existed or not, on top of the value
simply put, it always existed, and had a value
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

Post by Froggerprogger »

I think tinman meant, when we use :
Static a.l = 5 / 2
it could be compiled to an initialization at program start with no check-routine included inside the procedure.
But when we type:
Static a.l = anyVar + test() + 23;
then it could be compiled in a different way: simply add the "check-for-first-run - routine" inside the procedure.

This would be the optimum, I think (now :D )

For the programmer there would be no difference between:
Static a.l = 123
or Static a.l = myProc()
because he simply wants to initialize this static var one time. The speedthing could be solved during compilation (as above). The programmer needn't care about.
%1>>1+1*1/1-1!1|1&1<<$1=1
Post Reply