Use of Static

Use of Static - Use of Static THE MEANING OF "STATIC"...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Use of Static THE MEANING OF "STATIC" Someone asked about the meaning of the term "static" in C++. This particular term is perhaps the most overworked one in the language. It's both a descriptive word and a C++ keyword that is used in various ways. "static" as a descriptive term refers to the lifetime of C++ memory or storage locations. There are several types of storage: - static - dynamic (heap) - auto (stack) A typical storage layout scheme will have the following arrangement, from lowest to highest virtual memory address: text (program code) static (initialized and uninitialized data) heap (large virtual address space gap) stack with the heap and stack growing toward each other. The C++ draft standard does not mandate this arrangement, and this example is only an illustration of one way of doing it. Static storage thus refers to memory locations that persist for the life of the program; global variables are static. Stack storage comes and goes as functions are called ("stack frames"), and heap storage is allocated and deallocated using operators new and delete. Note that usage like: void f() { static int x = 37; } also refers to storage that persists throughout the program, even though x cannot be
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/27/2012 for the course CS 251 taught by Professor Staff during the Fall '08 term at Purdue.

Page1 / 3

Use of Static - Use of Static THE MEANING OF "STATIC"...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online