| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"" |
| Date: |
20 May 2006 01:33:55 PM |
| Object: |
correct way to use .h and #includes? |
In some senarios you want to include a file in two or more branches of
your project, what is the correct way to do this ? Can it be done
without #ifdef, or is that the correct way ?
.
|
|
| User: "Cy Edmunds" |
|
| Title: Re: correct way to use .h and #includes? |
20 May 2006 07:28:28 PM |
|
|
<vfunc@talktalk.net> wrote in message
news:1148150035.356607.282090@j73g2000cwa.googlegroups.com...
In some senarios you want to include a file in two or more branches of
your project, what is the correct way to do this ? Can it be done
without #ifdef, or is that the correct way ?
A common way to write a header is:
// yadda.h
#if !defined(YADDA_H)
#define YADDA_H
....
#endif // end of file
It's not that elegant, but the language doesn't really provide a better way.
.
|
|
|
| User: "Phlip" |
|
| Title: Re: correct way to use .h and #includes? |
20 May 2006 08:28:04 PM |
|
|
Cy Edmunds wrote:
vfunc wrote:
In some senarios you want to include a file in two or more branches of
your project, what is the correct way to do this ? Can it be done
without #ifdef, or is that the correct way ?
A common way to write a header is:
// yadda.h
#if !defined(YADDA_H)
#define YADDA_H
...
#endif // end of file
It's not that elegant, but the language doesn't really provide a better
way.
Google "include guards", and ain't this in the FAQ?
--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
.
|
|
|
| User: "" |
|
| Title: Re: correct way to use .h and #includes? |
21 May 2006 08:21:53 AM |
|
|
"It's not that elegant" which is why I was wondering if there was an
improved method. "include guards", sorry i could not imagine that it
would be called that, like Victor said they don't "hurt anybody" so
what are they protecting, is it the compiler ?
.
|
|
|
| User: "Victor Bazarov" |
|
| Title: Re: correct way to use .h and #includes? |
21 May 2006 09:59:33 AM |
|
|
wrote:
"It's not that elegant" which is why I was wondering if there was an
improved method. "include guards", sorry i could not imagine that it
would be called that, like Victor said they don't "hurt anybody" so
what are they protecting, is it the compiler ?
http://en.wikipedia.org/wiki/Include_guard
Or google "include guards" (as a phrase, with quotes) and read about
them in other sources.
.
|
|
|
|
|
|
|
| User: "Victor Bazarov" |
|
| Title: Re: correct way to use .h and #includes? |
20 May 2006 03:16:58 PM |
|
|
wrote:
In some senarios you want to include a file in two or more branches of
your project, what is the correct way to do this ?
Include it.
Can it be done
without #ifdef, or is that the correct way ?
Which #ifdef? Do you mean double inclusion guards? Put them it, they
don't hurt anybody.
V
--
Please remove capital As from my address when replying by mail
.
|
|
|
|
| User: "Jonathan Mcdougall" |
|
| Title: Re: correct way to use .h and #includes? |
20 May 2006 03:21:37 PM |
|
|
wrote:
In some senarios you want to include a file in two or more branches of
your project, what is the correct way to do this ? Can it be done without #ifdef,
or is that the correct way ?
Depends on what a "branch" is. You'll have to explain a bit more what
the problem is because right now the answer is "well.. just include
it". We ain't mind readers.
Jonathan
.
|
|
|
|

|
Related Articles |
|
|