Re: Defining variable in C header file related doubt
- From: lawrence.jones@xxxxxxxxxxx
- Date: Mon, 9 Jun 2008 16:29:43 -0400
whirlwindkevin <manumg007@xxxxxxxxx> wrote:
I saw a program source code in which a variable is defined in a header
file and that header file is included in 2 different C files.When i
compile and link the files no error is being thrown.How is this
possible.I thought it will throw "Variable redefinition Error". Giving
the source code for reference.Please help me out on this...
Having multiple definitions results in undefined behavior -- the
implementation is not required to diagnose it, and many (if not most)
implementations will not, particularly if the definitions are compatible
and the variable is not explicitly initialized. The code is still
wrong: the header should have only a declaration of the variable (with
extern) and exactly one source file should have the actual definition.
-- Larry Jones
OK, what's the NEXT amendment say? I know it's in here someplace. -- Calvin
.
- References:
- Defining variable in C header file related doubt
- From: whirlwindkevin
- Defining variable in C header file related doubt
- Prev by Date: Re: Re-use the argument?
- Next by Date: Re: printig effort
- Previous by thread: Re: Defining variable in C header file related doubt
- Next by thread: Avast - Free Antivirus
- Index(es):
Relevant Pages
|