473,586 Members | 2,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help with header files..

ok so i was just reading about #ifndef and header files. I have a few
doubts. It would be great help if someone can clear my doubts..

#ifndef A_H
#define A_H
....
code
.....
#endif

^^ lets say A.h is included in B.h which is included in C.h..so how
will the compiler resolve everything ??

also i saw some programs where there are many files like a.h, a.c,
b.h, b.c, c.h, c.c etc and then there is a all.h file
which goes like this -

#ifndef A_H
#include "a.h"
#endif

#ifndef B_H
#include "b.h"
#endif

#ifndef C_H
#include "c.h"
#endif
then only all.h is included in a.c, b.c and c.c

how did it work ??
Mar 6 '08 #1
1 1370
On 6 Mar, 07:30, johnnash <johnnas...@gma il.comwrote:
ok so i was just reading about #ifndef and header files. I have a few
doubts. It would be great help if someone can clear my doubts..
what are your "doubts"? You aren't clear about what is unclear!

#include "xyz.h"

simply means "include the text of the file xz.h here"

#ifndef A_H
if A_H (a preprocessor macro) is not defined then include (see above)
the following text.

#define A_H
define the preprocessor macro A_H. Subsequent
#ifndef A_H will not "fail"- that is *not* include
the following text

...
code
....
#endif
marks the end of the text taht is included after a "successful "
#if (or #ifdef or #ifndef etc).
^^ lets say A.h is included in B.h which is included in C.h..so how
will the compiler resolve everything ??
what is the problem? Suppose D.c includes C.h and you compile D.c
This is what the compiler sees after the preprocessor has been.
I've added indents to make it clearerer. I've skiiped A.h as I got
bored :-)
D.c
#include C.h
#ifndef C_H
#define C_H
#include B.h
#ifndef B_H
#define B_H
B code
#endif
C code
#endif

I don't see the problem

also i saw some programs where there are many files like a.h, a.c,
b.h, b.c, c.h, c.c etc and then there is a all.h file
*which goes like this -

#ifndef A_H
#include "a.h"
#endif
this simply does the test outside the header a.h file.
It arguably makes for a faster compile (a.h is never
openened) but I find it harder to administer and harder
to read (zillions of #ifndefs to amnage)

#ifndef B_H
#include "b.h"
#endif

#ifndef C_H
#include "c.h"
#endif

then only all.h is included in a.c, b.c and c.c

how did it work ??
again I don't see the problem...
a.c includes all.h which includes a.h, b.h and c.h.

Is it the recursion that bothers you. An include file
including an include file?

Try working through some examples on paper
--
Nick Keighley

Mar 6 '08 #2

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

Similar topics

5
3617
by: | last post by:
I am having a major problem with file transfers - they are ending early when the bandwidth tops-out. Smaller files transfer just fine, but large files (12Mb+) can 'abort' the transfer after maybe 35%-60% complete. I'm sending large MP3 files from my website www.TheDoctorDementoShow.com but the users are pretty upset because the files are...
3
5118
by: dharmesh Gupta | last post by:
Hi All, i am new to header files , and have a basic question , i have made my program in three files namely, idr_bpl.cpp( contains class definitions and function definitions) bpl.cpp( contains main() function) bpl.h (contains variable definition of a variable that is shared in the above two files )
11
2742
by: Steven T. Hatton | last post by:
In the past there have been lengthy discussiions regarding the role of header files in C++. People have been very adamat about header files serving as in interface to the implementation. I do understand the objective. This example may represent an interface in need of a bit of refactoring, but it goes to demonstrate the basic idea as I...
8
5460
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I...
18
2730
by: John Smith | last post by:
Hi all What does the group think of the practise of including one header file from inside another? I have some legacy code where this has been done, and it creates a dependency on a module (collection of files) which are not required, except for one header file's contents. I'd say 'No, header files should be included in the C source,...
4
1427
by: crs2003c | last post by:
For some time now, other teachers have had this problem. Visual C++ 6.0 was once installed on a WIN98 platform and apstring.h and graphic.h worked. However, since moving to WIN2000 and WINXP, these header files are missing. Where can I find these header files?? I have tried to create these headers over again, even CUT/PASTE, however, I...
22
2111
by: macAWM | last post by:
Hi list, First let me explain that my background is in Java and I am quite spoiled to its niceties (read "less ambiguous nature"). Anyway to my problems. 1. I want to write my own library for what I consider to be some holes in the standard language. How do I go about writing and compiling this without this stupid error about not having a...
1
1919
by: ligong.yang | last post by:
Hi all, I got tortured by a very weird problem when I was using k. wilder's random generator class in my program. PS: wilder's generator class can be found at http://oldmill.uchicago.edu/~wilder/Code/random/. Firstly, I got the notorious "fatal error C1010: unexpected end of file while looking for precompiled header directive" error when...
1
1916
by: ligong.yang | last post by:
Hi all, I got tortured by a very weird problem when I was using k. wilder's random generator class in my program. PS: wilder's generator class can be found at http://oldmill.uchicago.edu/~wilder/Code/random/. Firstly, I got the notorious "fatal error C1010: unexpected end of file while looking for precompiled header directive" error when...
0
6526
by: shrik | last post by:
I have following error : Total giant files in replay configuration file are : File name : /new_file/prob1.rec Given file /new_file/prob1.rec is successfully verified. Splitting for giant file /new_file/prob1.rec started. Please wait.... In while loop of request searching *** glibc detected *** ./a.out: free(): invalid next size (normal):...
0
8200
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7954
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8215
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
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 we have to send another system
0
1179
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.