Path: csiph.com!1.us.feeder.erje.net!2.us.feeder.erje.net!feeder.erje.net!1.eu.feeder.erje.net!weretis.net!feeder4.news.weretis.net!border2.nntp.ams1.giganews.com!nntp.giganews.com!buffer1.nntp.ams1.giganews.com!buffer2.nntp.ams1.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail NNTP-Posting-Date: Tue, 07 Feb 2017 12:29:35 -0600 From: Gareth Owen Newsgroups: comp.lang.c Subject: Re: How to compile several C files References: <137458b9-1471-27ef-8c1e-8d9e781f315f@verizon.net> Date: Tue, 07 Feb 2017 18:29:35 +0000 Message-ID: <874m05kg6o.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) Cancel-Lock: sha1:3vRkxaNuvrPR/dlZ3t73ewvO6NA= MIME-Version: 1.0 Content-Type: text/plain Lines: 31 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-OJDEcV+hajTI5yLaCawGvbUhu/4VWv+PdlPpAALULJz+3ELEXepo+wpti5gC1D9Vpg01c5JMGEW0iBn!5N2xnq7UYd2DVK/quD0PmkY6xHYzTsCEZHkPJMdQkmtnqBu0pPjq1WQ7WoHaq84aZPOkIyM= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2294 Xref: csiph.com comp.lang.c:103406 Keith Thompson writes: > "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. As an interesting exercise for Bart and Malcolm, I recommend that they put extern balance *bal; in the .h file and balance bal[YEARS]; in the .c file, and rely on the the equivalence of arrays and pointers.