Reputation: 1132
Example in C, Static variables have a property of preserving their value even after they are out of their scope. Hence, static variables preserve their previous value in their previous scope and are not initialized again in the new scope.
How can I achieve the same functionality in Ada language where the variable is ensured to live until the end of the progran but its scope should be limited to the function hence also ensuring data coupling?
Upvotes: 1
Views: 178
Reputation: 6611
Variables declared directly in package specifications and bodies retain their state as long as the program is running.
You can't keep variables local to a subprogram as such, but you can declare a single subprogram inside a package, and declare the persistent variables in the body of the package.
Upvotes: 1