I think this came up in conversation with one of you, but I can't remember who or when. So here it is, for your reading pleasure. I wrote this for myself because I had to use C and couldn't remember this stuff to save my life. C declarations by Julie Sussman 14 January 1983 This note attempts to explain the concepts associated with the scope and extent of C declarations The designers of C appear to have been unfamiliar with programming language terminology and concepts such as static/dynamic, local/global, etc. As a result, they use some of these same words differently, both in language description and in language key words. Where there could be confusion, I will try to keep these uses distinct by putting C language terminology in quotes (e.g., "static") and C keywords in uppercase (e.g., STATIC). Any other words are ordinary English terminology (e.g., static). Table of Contents 1. Declaration and Definition 2. Internal and External 3. Static and Dynamic 4. Local and Global - scope of names 5. Getting access to external definitions 6. Review of STATIC and EXTERN 1. Declaration and Definition A "declaration" may serve either to define something and make its name usable or just to make its name usable. Declarations may 1. Define a variable: Give all of its properties (type etc.) and cause any necessary storage allocation and initialization. 2. Define a function: Give all of its properties (return type, parameters, etc.) and its implementation (function body). 3. Declare a variable: Give all of its properties, so it can be used, but don't do any storage allocation or initialization, since that was done in the definition. 4. Declare a function: Give just its type and name, so it can be used, but don't mention its parameters or give its body, since that was done in the definition. There may be any number of declarations of a variable or function in a [multi-file] program, since it may be used in many separate places. But of course only one of these declarations can be the definition of the variable or function. You can easily tell whether or not a function is being defined by the presence of its body. You can tell whether a variable is being defined by the presence or absence of the keyword EXTERN (to be discussed in a later section). Examples: int factorial(n) /* declare and define */ int n; { if (n==1) return 1; else return n*factorial(n-1); } int factorial(); /* declare, don't define */ int x; /* declare and define */ extern int x; /* declare, don't define */ 2. Internal and External An "internal" declaration is one that occurs inside a function body. This can only be a variable declaration, not a function. An "external" declaration is on that is outside any function. This includes function declarations as well as variable declarations. For example: int x; /* external */ int foo() /* external */ { int y; /* internal */ } 3. Static and Dynamic In normal programming terminology, a variable may be o static: Its storage is permanently allocated; it is initialized only once, when allocated; its value is retained across any sequence of function calls and returns. o dynamic or automatic: Its storage is allocated each time some block in a function is entered; it is initialized eah time it is allocated; its value is not retained after the block is exited. In C, there is no term for static variables. The term "static" and the keyword STATIC mean something else. The storage of a static variable is sometimes described as statically allocated. Dynamic variables are referred to as "automatic" in C. 4. Local and Global - scope of names This section discusses the local or global nature of "definitions" (those declarations that define variables or functions).