linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Robert P. J. Day" <rpjday@mindspring.com>
To: nhorman@tuxdriver.com
Cc: C programming list <linux-c-programming@vger.kernel.org>
Subject: Re: weird structure definition in header file
Date: Tue, 6 Sep 2005 15:27:35 -0400 (EDT)	[thread overview]
Message-ID: <Pine.LNX.4.63.0509061526130.24776@vericenter> (raw)
In-Reply-To: <20050906192324.GA10879@hmsreliant.homelinux.net>

On Tue, 6 Sep 2005, nhorman@tuxdriver.com wrote:

> On Tue, Sep 06, 2005 at 03:13:48PM -0400, Robert P. J. Day wrote:
> >
> >   i'm looking at some legacy code and, in a header file, i find the
> > following (paraphrased for brevity):
> >
> > typedef struct {
> > 	... stuff ...
> > } Widgets ;
> >
> > extern Widgets Widget ;
> >
> >
> >   huh?  i can see why a header file would want to define a structure
> > but i'm confused why the *header* file would then refer to an external
> > object of that type.  that's a new one on me -- typically, i'd expect
> > a *source* file to define such a thing and other *source* files to
> > contain the "extern" declaration.
> >
> >   is this some subtle programming cleverness of which i am unaware?
> > thanks.
> >
> This is done quite frequently when a data structure needs to be
> referenced from multiple locations.  They're not necessicarily
> consecutive like that, but its rather a common practice to extern a
> instance of a type in a header file.  The kernel source tree does
> this very frequently, check include/net/ipv4 for lots of examples.

ok, so what it represents is just a shortcut so that each source file
doesn't have to have its own extern, it just comes along with the
header file.  all right, i guess i can live with that although it
strikes me as just a little bit sleazy.  oh, well.

rday

  reply	other threads:[~2005-09-06 19:27 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-06 19:13 weird structure definition in header file Robert P. J. Day
2005-09-06 19:23 ` nhorman
2005-09-06 19:27   ` Robert P. J. Day [this message]
2005-09-06 19:45     ` Robert P. J. Day
2005-09-06 19:56       ` nhorman
2005-09-07  1:20       ` Glynn Clements
2005-09-07  1:17     ` Glynn Clements
2005-09-06 19:57   ` Steve Graegert
2005-09-06 20:24 ` Ronaldo.Afonso

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=Pine.LNX.4.63.0509061526130.24776@vericenter \
    --to=rpjday@mindspring.com \
    --cc=linux-c-programming@vger.kernel.org \
    --cc=nhorman@tuxdriver.com \
    /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).