Re: keyword extern
From: Yashesh Bhatia (yasheshb_at_gmail.com)
Date: 06/26/04
- Next message: Pierre Maurette: "Re: printf for a char in hex - why all the F's?"
- Previous message: Emmanuel Delahaye: "Re: VB code to C"
- In reply to: tweak: "keyword extern"
- Next in thread: Emmanuel Delahaye: "Re: keyword extern"
- Reply: Emmanuel Delahaye: "Re: keyword extern"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 26 Jun 2004 00:41:45 -0700
tweak <xbwaichunasx@cox.net> wrote in message news:<0a3Dc.3$151.1@fed1read02>...
> What's the best way to use extern when using multiplefiles that is
> easiest to maintain?
>
> Is it best to declare:
>
> extern int a;
>
> in a header file and include the header file in all files except
> where it's defined.
>
> Or is it better to write
>
> extern int a;
>
> in all the files except where it's originally defined?
>
> I'm just curious what the best practice is since I code
> as a hobby. And I'm still learning and making lotsa
> mistakes.
>
> Thanks,
>
> Brian
>
> P.S. Thanks to whomever recommended Advanced Unix Programming
> Second Edition. It's cleared up a lot for me. And it's
> making me question as to whether I should drop linux and
> move to openBSD.
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.
- 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.
- Next message: Pierre Maurette: "Re: printf for a char in hex - why all the F's?"
- Previous message: Emmanuel Delahaye: "Re: VB code to C"
- In reply to: tweak: "keyword extern"
- Next in thread: Emmanuel Delahaye: "Re: keyword extern"
- Reply: Emmanuel Delahaye: "Re: keyword extern"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|