Re: global variable declaration in header
- From: nszabolcs <nszabolcs@xxxxxxxxx>
- Date: 31 May 2007 09:11:27 -0700
Richard Tobin wrote:
In article <1180607788.103356.144860@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,thanks
nszabolcs <nszabolcs@xxxxxxxxx> wrote:
So is this style acceptable? (see example below)[...]
// common.h:
int i;
void print();
void inc();
This is not good style. It defines (rather than merely declares) the
variable i in each file that includes common.h. Though, as the
standard and FAQ state, this works on many systems, it is better to
say what you mean, and merely declare i in the header file with
"extern int i", and define it in one of the .c files with "int i".
i like minimalistic code, but it seems it's not quite ok to leave out
extern here
.
- References:
- global variable declaration in header
- From: nszabolcs
- Re: global variable declaration in header
- From: Richard Tobin
- global variable declaration in header
- Prev by Date: Re: HELP!! Two questions from <<the c programming language>>
- Next by Date: Re: I've read K&R, what now?
- Previous by thread: Re: global variable declaration in header
- Next by thread: Re: global variable declaration in header
- Index(es):
Relevant Pages
|