View previous topic :: View next topic
|
Author |
Message |
Prabha Warnings : 2 New User
Joined: 05 Dec 2005 Posts: 79
|
|
|
|
Hi,
Can anyone explain me the usage of static varible. Is static varible is only for storage purpose or to keep value. Please explain me with examples. I searched in other forums. But it was not clear. |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
Can you provide a link to where you found a reference to the term static variable? |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
In your terms, what is the difference between "storage purposes" and "keep a value"?
STATIC vars are a PL/I concept. From a web-link:
Quote: |
Storage. PL/I provides a number of storage attributes. The default is AUTOMATIC, which is allocated on entry to a block, possibly with initialization, and freed at exit. STATIC storage exists throughout the life of the program, |
|
|
Back to top |
|
|
ruodeer
New User
Joined: 06 Jul 2007 Posts: 58 Location: home
|
|
|
|
as saying:static for batch program..automatic for online program. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Do you mean an Assembler constant (DC)?
Code: |
EYECTCHR DC CL38'HELLO, I AM A CONSTANT, LEAVE ME ALONE'
|
HTH....
Regards,
Bill |
|
Back to top |
|
|
u770624
New User
Joined: 12 Jul 2006 Posts: 2 Location: Blighty
|
|
|
|
Illustration on use of static variables ...
Module_A calls Module_B ( and it can do so many times )
Module_B needs to know when it is called for the first time (probably as an efficiency measure)
Therefore Module_B declares a STATIC variable and initialises it to a known value.
Module_B checks the static variable every time it is called and if it is the known, initiallised value then it is the first time it is called. Module_B then performs the first time logic AND sets the static variable to a different value.
On subsequent calls, the value is no longer the initiallised value.
If it was not a static variable then it would be a dynamic variable and would be set to the initiallised value every time Module_B was called. |
|
Back to top |
|
|
Mistermind
New User
Joined: 08 Feb 2008 Posts: 46 Location: Dublin
|
|
|
|
Static storage is mapped just once inside the PL/I loadmodule, similar to WORKING-STORAGE variable in cobol. Automatic variables are allocated new storage space each time you invoke the subroutine B, so if your subroutine B declares AUTO variables, your partition will very quickly run out of space. This problem will not arise if STATIC variable is declared. If subroutine needs to ensure a certain value in a static variable, e.g. zero, it can be set each time subroutine gains control.
PL/I STATIC variables are also easier to find in storage, always addressed by register 3. |
|
Back to top |
|
|
|