Re: global variable declaration in header
- From: richard@xxxxxxxxxxxxxxx (Richard Tobin)
- Date: 31 May 2007 13:36:14 GMT
In article <1180607788.103356.144860@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
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".
This matches what you do with functions, except that a function
declaration implicitly has then "extern" anyway. Some people prefer
to explicitly write "extern" even on function declarations, for
consistency.
-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
.
- Follow-Ups:
- Re: global variable declaration in header
- From: nszabolcs
- Re: global variable declaration in header
- References:
- global variable declaration in header
- From: nszabolcs
- global variable declaration in header
- Prev by Date: Re: small C compiler that will run on Vista
- Next by Date: Re: can any bdy help me
- Previous by thread: global variable declaration in header
- Next by thread: Re: global variable declaration in header
- Index(es):
Relevant Pages
|