|
-
Oct 19th, 2009, 05:21 PM
#1
Thread Starter
Member
Where may Static statements appear?
I know they can appear in local procedure's, but can they appear in a "block of code" as well?
-
Oct 19th, 2009, 06:33 PM
#2
Re: Where may Static statements appear?
When you tried it for yourself, what happened? If it worked then the answer is yes, otherwise it's no.
-
Oct 19th, 2009, 07:01 PM
#3
Re: Where may Static statements appear?
What is a 'block of code'? Do you mean something like "within an If statement", or "in a file".
The simplest solution is to try it, as JM stated, but it would also be good to reason through it. If your meaning is the former of those two options, in what way would a variable declared in a local procedure be different when located within such a block? The answer is that both are local variables, so there is no difference other than the scope of the variable. Therefore, since you already know that they can appear in local procedures, then you know that they can appear on local variables, and a variable declared at the top of a procedure is no different from one declared later in the procedure from that perspective.
Alternatively, where would a static variable be located? It had best not be created within the stack frame of a procedure, like other local variables, because if it was, then it would be destroyed when the stack frame gets destroyed on function exit. Therefore, the static has to be located on the heap, as that's the other choice. Unfortunately, that would suggest that the static variable can be ANYWHERE, but we know (by looking at where local variables can be declared) that the compiler can enforce scoping issues regardless of where a variable is declared, in which case you'd need to check.
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|