Re: struct question
From: CBFalconer (cbfalconer_at_yahoo.com)
Date: 08/05/04
- Next message: CBFalconer: "Re: The one who can't C"
- Previous message: Richard Bos: "Re: Null pointers"
- In reply to: pete: "Re: struct question"
- Next in thread: pete: "Re: struct question"
- Reply: pete: "Re: struct question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 05 Aug 2004 13:09:49 GMT
pete wrote:
>
... snip ...
>
> For matched pairs of .c and .h files:
> I am inclined not to put extern object declarations in a header.
> I think they belong in the .c file.
> If a.c used "extern struct e d", any other .c file linking with a.c,
> wouldn't need to know which external objects were being used in a.c,
> so therefore "extern struct e d",
> should be declared in a.c, instead of in a.h.
You won't go wrong if you consider the .h file as a means of
publicizing those portions of the .c file you want to make
accessible to other compilation units. Thus you declare and
define the objects in the .c file. If the objects are NOT to be
accessible externally you mark them static. If they ARE to be
accessible externally you declare them in the .h file, and use the
extern keyword for objects other than function prototypes.
Similarly you put typedefs and macros in the .h file ONLY when you
need to have them available to other compilation units.
-- "I'm a war president. I make decisions here in the Oval Office in foreign policy matters with war on my mind." - Bush. "Churchill and Bush can both be considered wartime leaders, just as Secretariat and Mr Ed were both horses." - James Rhodes. "If I knew then what I know today, I would still have invaded Iraq. It was the right decision" - G.W. Bush, 2004-08-02
- Next message: CBFalconer: "Re: The one who can't C"
- Previous message: Richard Bos: "Re: Null pointers"
- In reply to: pete: "Re: struct question"
- Next in thread: pete: "Re: struct question"
- Reply: pete: "Re: struct question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|