home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / c / 13448 < prev    next >
Encoding:
Internet Message Format  |  1992-09-09  |  1.8 KB

  1. Path: sparky!uunet!sun-barr!olivea!gossip.pyramid.com!pyramid!oracle!unrepliable!bounce
  2. From: wkaufman@us.oracle.com (William Kaufman)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: extern struct
  5. Message-ID: <1992Sep10.034330.28441@oracle.us.oracle.com>
  6. Date: 10 Sep 92 03:43:30 GMT
  7. References: <1428@yetti.UUCP>
  8. Sender: usenet@oracle.us.oracle.com (Oracle News Poster)
  9. Organization: Oracle Corporation, Redwood Shores CA
  10. Lines: 34
  11. Nntp-Posting-Host: hqsun2.us.oracle.com
  12. X-Disclaimer: This message was written by an unauthenticated user
  13.               at Oracle Corporation.  The opinions expressed are those
  14.               of the user and not necessarily those of Oracle.
  15.  
  16. In article <1428@yetti.UUCP> g-yao@cs.yorku.ca (Ling Yao) writes:
  17. ] ----------------file 1------------------------------
  18. ]     static struct point p[100][100];
  19. ] -----------------------------------------------------
  20. ] ------------------file 2----------------------------
  21. ] extern struct point p[100][100];
  22. ] ---------------------------------------------------
  23.  
  24.     "static" means two different things at once:
  25.  
  26.         1) The item is local to its scope (either file or function), and
  27.     cannot be accessed directly from outside that scope: no extern
  28.     references allowed.
  29.  
  30.         2) The item has duration: even if it's declared inside a
  31.     function, its value will be consistent between function calls.
  32.  
  33.     The problem you've got is #1.  The simplest way to deal with this
  34. is:
  35.  
  36.     - Put the struct declaration and the extern reference in a header
  37. file, included by both file 1 and 2.
  38.  
  39.     - Put the definition of p *without the "static"* in file 1.
  40.  
  41.                                            -- Bill K.
  42.  
  43. Bill Kaufman,          | "...all conscious species are plastic and
  44. Corporate Lackey       |  all plastic species are conscious."
  45. wkaufman@us.oracle.com |                     -- Yew-Kwang Ng
  46.