473,403 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

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 1351
On 6 Mar, 07:30, johnnash <johnnas...@gmail.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
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...
3
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(...
11
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...
8
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 -------------------------------------------------------------------------------- ...
18
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...
4
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,...
22
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...
1
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...
1
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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...
0
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,...
0
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...

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.