Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: How to compile several C files Date: Tue, 07 Feb 2017 09:22:35 -0800 Organization: None to speak of Lines: 32 Message-ID: References: <137458b9-1471-27ef-8c1e-8d9e781f315f@verizon.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="04056ce4c9c7dd85ee7ce897aab9f52a"; logging-data="1810"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19vxkVcGMUIwFycVQMuWEVL" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:ehISADuFsJodsORtlhdOlMSSe/o= sha1:LuJ0lUYhcw0b9JG9pZcoHkqyrm8= Xref: csiph.com comp.lang.c:103392 "James R. Kuyper" writes: [...] > All of the following are object definitions. They do NOT belong in a > header file - you need to move each of these definitions to one or the > other of the *.c files. If an object's name is used in both *.c file, > you should have a declaration for that object in one of the two header > files. But that declaration would look different from from these > definitions. At a minimum, you would put "extern" at the beginning of > each declaration. Also, for the arrays, it's not necessary to put the > actual number of elements in the object declaration, only in the object > definition. It's not necessary to include the length in the declaration. For example you could have extern balance bal[]; in a .h file and balance bal[YEARS]; in the corresponding .c file. But *if* it makes sense to declare an array object in a header, then it's not necessarily a bad idea to include the bounds in the declaration. It lets you use `sizeof bal / sizeof bal[0]` to compute the number of elements, for example. On the other hand, it's likely better not to make the array object's name globally visible in the first place. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"