473,480 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 ?

May 21 '06 #1
6 1440
vf***@talktalk.net 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
May 21 '06 #2
vf***@talktalk.net 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

May 21 '06 #3

<vf***@talktalk.net> wrote in message
news:11**********************@j73g2000cwa.googlegr oups.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.
May 21 '06 #4
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!!!
May 21 '06 #5
"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 ?

May 21 '06 #6
vf***@talktalk.net 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.
May 21 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
2705
by: Tim Tyler | last post by:
A fairly simple question: I have a library A which depends on library B and C. Currently I have: <?php include("A.inc.php"); include("B.inc.php"); include("C.inc.php");
7
4762
by: Alex Hunsley | last post by:
I'm making a web site that does login authentication. It all works fine, but I have a question about 'correctness'... Certain php scripts on the site should only run in the user has logged on....
2
1596
by: Joe Mowry | last post by:
First off, I'm posting this question for a friend that doesn't have access to the news groups. Problem: Using PHP as the base and has several PHP < includes > for various functions, all this...
4
1619
by: Patrick | last post by:
I have an ASP site with about 50 ASP files, all of which are currently including a common "includes.asp" file near the top of the file, responsible for generating the <HEAD/> section of the HTML ...
12
2966
by: tshad | last post by:
I am not sure why I am getting this error: I have the following code I want to run from another include file that holds all my functions. functions.inc...
6
2852
by: William F. Zachmann | last post by:
We've got a project going that involves moving an old web site with a massive dll written in C++ that produces most of the output from a SQL 7.0 data base on NT4 onto IIS on Windows 2003 Server...
3
2512
by: Jeff | last post by:
I have an asp page. Now I know this is sortof OT, but I am not sure of the forum to get an answer. I have an include on this asp page <!-- #include file=\forum\includes\consts-inc.asp --> ...
27
2805
by: pamela fluente | last post by:
Hello, for the following code, VS suggests that construct (width= height= ) is out of date and a newer one is recommended: <table><tr><td width="92" height="38" valign="middle">AnyThing</td></...
4
1816
by: Ron | last post by:
Hi all, Trying to work out a few problems in using php on my site. Partially this is a html question. I was reading a lot of the posts and it seems that some of the includes people are using are...
0
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7048
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
6956
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4783
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4485
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2986
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
183
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.