File: static.c

package info (click to toggle)
c-cpp-reference 2.0.2-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 8,012 kB
  • ctags: 4,612
  • sloc: ansic: 26,960; sh: 11,014; perl: 1,854; cpp: 1,324; asm: 1,239; python: 258; makefile: 115; java: 77; awk: 34; csh: 9
file content (47 lines) | stat: -rw-r--r-- 1,031 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 * Author: M.J Leslie.
 * Purpose: To demonstrate the 'static' storage class 
 */

void func1(void);

static count=10;		/* Global variable - static is the default */

main()
{
  while (count--) func1();

}

/***************************************************************************/

void func1(void)
{
				/* 'thingy' is local to 'func1' - it is 
				 * only initalised at run time. Its value
				 * is NOT reset on every invocation of
				 * 'func1'
				 */
  static thingy=5;
  thingy++;
  printf(" thingy is %d and count is %d\n", thingy, count);
}


/**************************************************************************

Program )/P looks like this:

 thingy is 6 and count is 9
 thingy is 7 and count is 8
 thingy is 8 and count is 7
 thingy is 9 and count is 6
 thingy is 10 and count is 5
 thingy is 11 and count is 4
 thingy is 12 and count is 3
 thingy is 13 and count is 2
 thingy is 14 and count is 1
 thingy is 15 and count is 0

**************************************************************************/