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.
Yep.
> all right, i guess i can live with that although it strikes me as
> just a little bit sleazy. oh, well.
Huh? That's what header files are for. Or do you have stuff like:
extern int strcmp(const char *s1, const char *s2);
at the top of all of your source files?
--
Glynn Clements <[EMAIL PROTECTED]>
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming"
in
the body of a message to [EMAIL PROTECTED]
More majordomo info at http://vger.kernel.org/majordomo-info.html