home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_04 / allison / namspace.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-10  |  1.4 KB  |  46 lines

  1. LISTING 7 - Illustrates Namespaces
  2.  
  3. *** NOTE to EDITOR: This must be set in small type and perhaps
  4. span across the page to stay intact - IT MUST NOT WRAP!
  5. Thank you. ***
  6.  
  7. /* namspace.c:  Illustrate namespaces */
  8.  
  9. #include <stdio.h>
  10.  
  11. struct foo                                      /* tag-global */
  12. {
  13.     int foo;                                    /* global-foo-member */
  14. };
  15.  
  16. struct foo foo;                                 /* ordinary-global
  17.                                                    (not used) */
  18.  
  19. main()
  20. {
  21.     struct foo foo;                             /* tag-global, ordinary-main-1 */
  22.  
  23.     goto foo;                                   /* label-main */
  24.  
  25. foo:                                            /* label-main */
  26.     foo.foo = 1;                                /* ordinary-main-1, global-foo-member */
  27.     printf("struct foo == {%d}\n",foo.foo);     /* ordinary-main-1, global-foo-member */
  28.  
  29.     {
  30.         int foo = 2;                            /* ordinary-main-2 (new scope) */
  31.         struct foo x;                           /* tag-global */
  32.  
  33.         x.foo = foo+1;                          /* global-foo-member, ordinary-main-2 */
  34.         printf("foo == %d\n",foo);              /* ordinary-main-2 */
  35.         printf("struct foo == {%d}\n",x.foo);   /* global-foo-member */
  36.     }
  37.     return 0;
  38. }
  39.  
  40. /* Output:
  41. struct foo == {1}
  42. foo == 2
  43. struct foo == {3}
  44. */
  45.  
  46.