linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan-Benedict Glaw <jbglaw@lug-owl.de>
To: linux-c-programming@vger.kernel.org
Subject: Re: extern storage class & multiple declaration
Date: Thu, 22 Aug 2002 10:02:53 +0200	[thread overview]
Message-ID: <20020822080253.GR10730@lug-owl.de> (raw)
In-Reply-To: <20020822075234.20104.qmail@relay1.home.ro>

[-- Attachment #1: Type: text/plain, Size: 1371 bytes --]

On Thu, 2002-08-22 07:52:34 -0000, Alina Valea <avalea@home.ro>
wrote in message <20020822075234.20104.qmail@relay1.home.ro>:
> Hello everybody,
> 
> Suppose we have:

[
	file.h declares a variable,
	file.c defines it, but doesn't use it and
	some_file.c includes file.h and uses mentioned variable
]

> I know this is entirely correct, but is it an acceptable
> programming habit?

This is not only correct but also done very often. Sometimes, you can't
go around global variables. In such a case, it's better to have a
"globals.h" (declaring *all* global variables) and a matchins globals.c
file (defining them all, possibly initializing them to useful default
values).

This is a _lot_ better than spreading all those global variables over a
zillion .c files, and locally declaring them in any .c file which uses
(but doesn't define) it. That's quite error-prone (eg. small things like
signed <-> unsigned conflicts *will* come up at some time, and you'll
spend a day or two for searching the difference).

Having all global variables (if any exist) iat one place (in conjunction
with a matching header file) is a good thing helping to not do stupid
mistakes...

MfG, JBG

-- 
Jan-Benedict Glaw   .   jbglaw@lug-owl.de   .   +49-172-7608481
	 -- New APT-Proxy written in shell script --
	   http://lug-owl.de/~jbglaw/software/ap2/

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

      reply	other threads:[~2002-08-22  8:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-22  7:52 extern storage class & multiple declaration Alina Valea
2002-08-22  8:02 ` Jan-Benedict Glaw [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020822080253.GR10730@lug-owl.de \
    --to=jbglaw@lug-owl.de \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).