home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sun-barr!olivea!gossip.pyramid.com!pyramid!oracle!unrepliable!bounce
- From: wkaufman@us.oracle.com (William Kaufman)
- Newsgroups: comp.lang.c
- Subject: Re: extern struct
- Message-ID: <1992Sep10.034330.28441@oracle.us.oracle.com>
- Date: 10 Sep 92 03:43:30 GMT
- References: <1428@yetti.UUCP>
- Sender: usenet@oracle.us.oracle.com (Oracle News Poster)
- Organization: Oracle Corporation, Redwood Shores CA
- Lines: 34
- Nntp-Posting-Host: hqsun2.us.oracle.com
- X-Disclaimer: This message was written by an unauthenticated user
- at Oracle Corporation. The opinions expressed are those
- of the user and not necessarily those of Oracle.
-
- In article <1428@yetti.UUCP> g-yao@cs.yorku.ca (Ling Yao) writes:
- ]
- ] ----------------file 1------------------------------
- ]
- ] static struct point p[100][100];
- ]
- ] -----------------------------------------------------
- ]
- ] ------------------file 2----------------------------
- ] extern struct point p[100][100];
- ] ---------------------------------------------------
-
- "static" means two different things at once:
-
- 1) The item is local to its scope (either file or function), and
- cannot be accessed directly from outside that scope: no extern
- references allowed.
-
- 2) The item has duration: even if it's declared inside a
- function, its value will be consistent between function calls.
-
- The problem you've got is #1. The simplest way to deal with this
- is:
-
- - Put the struct declaration and the extern reference in a header
- file, included by both file 1 and 2.
-
- - Put the definition of p *without the "static"* in file 1.
-
- -- Bill K.
-
- Bill Kaufman, | "...all conscious species are plastic and
- Corporate Lackey | all plastic species are conscious."
- wkaufman@us.oracle.com | -- Yew-Kwang Ng
-