Re: keyword extern
From: Emmanuel Delahaye (emdelYOURBRA_at_noos.fr)
Date: 06/26/04
- Next message: Minti: "Re: preprozessor and #define Problem"
- Previous message: umbs.sairam_at_gmail.com: "Re: keyword extern"
- In reply to: Yashesh Bhatia: "Re: keyword extern"
- Next in thread: umbs.sairam_at_gmail.com: "Re: keyword extern"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 26 Jun 2004 08:11:28 GMT
In 'comp.lang.c', yasheshb@gmail.com (Yashesh Bhatia) wrote:
>> Or is it better to write
>>
>> extern int a;
>>
>> in all the files except where it's originally defined?
>>
> Well, my preferred way would be to declare it in all the .c files that
> need the extern variable rather than put the extern declaration in the
> header file and include the header file in the c files. The reason
> being.
>
> - If the variable was used by all c files, it would be better to make
> it a global variable in the .h file.
No. A header is certainely not the place for an object definition for an
obvious reason. If you include the header in more than one compile unit, you
will have more than one definition of the object with the same name. This is
the kind of situation a linker can't handle, except by an error message.
> - Keeping the extern declaration in the .c file instead of the .h
> file will make it easier for other .c files that dont need the extern
> variable but need other declarations from the .h file to include it.
The maintainers of such a code will doom you for ever. Please don't do that.
The OP's first proposal was nearly the good one. Please read my previous
answer to learn why.
-- -ed- get my email here: http://marreduspam.com/ad672570 The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99 FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
- Next message: Minti: "Re: preprozessor and #define Problem"
- Previous message: umbs.sairam_at_gmail.com: "Re: keyword extern"
- In reply to: Yashesh Bhatia: "Re: keyword extern"
- Next in thread: umbs.sairam_at_gmail.com: "Re: keyword extern"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|