Static Arrays and pre-initialized data

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Post Reply
spamiam
Posts: 739
Joined: 13 November 2005, 6:39 AM

Static Arrays and pre-initialized data

Post by spamiam »

I want to have a Static array in a subroutine, and I want to prevent it from being re-initialized with the same data every time the subroutine is called (to speed up processing), will a Static array be initialized only once, and then never again even thought there are a few instructions placing data into the array at the beginning of the subroutine?

-Tony
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Static Arrays and pre-initialized data

Post by dkinzer »

spamiam wrote:will a Static array be initialized only once
Yes. All statically allocated variables, whether defined at the module level or with the static attribute within a procedure, are initialized early in the startup process before Main() is invoked.

Defining a variable with the static attribute within a procedure gives you exactly the same effect as defining a variable at the module level except that it can only be seen from within the procedure.
- Don Kinzer
Post Reply