tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: style(5) proposal: forbid extern in .c



> [...] I wonder how we can resolve this case:

> extern struct netif_stats	le_stats[];
> 
> static struct netif_dif le_ifs[] = {
> /*	dif_unit	dif_nsel	dif_stats	dif_private	*/
> {	0,		NLE0CONF,	&le_stats[0],	le0conf,	},
> };
> #define NLE_IFS (sizeof(le_ifs) / sizeof(le_ifs[0]))
> 
> struct netif_stats le_stats[NLE_IFS];

That is not an extern declaration from a conceptual point of view; it's
just a forward declaration which happens to be implemented with a
(redundant) "extern" keyword.  (Even strict def/ref systems must
implement the tentative-definition paradigm for multiple declarations
within a single translation unit - C99 6.9.2, paragraph 2 in
particular.)

Still, I think it could be improved.

I would say that:

- If le_stats is - or might be, eg, depending on #defines - used from
   another file, the extern declaration should be moved into a .h used
   by both files.

- If not, the extern should be converted to static and the later
   declaration should have static added to it.

(I really wish C had chosen a different keyword for linkage control of
file-scope declarations; overloading static for storage duration
control at block scope and linkage control at file scope is ugly and
confusing.)

/~\ The ASCII				  Mouse
\ / Ribbon Campaign
 X  Against HTML		mouse%rodents-montreal.org@localhost
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B


Home | Main Index | Thread Index | Old Index