473,395 Members | 1,919 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,395 software developers and data experts.

Regarding multiple inclusion of files

Hi,

If I include a ".h" file for multiple times, will it increase my
program size??

Regards
Ram.
Dec 6 '07 #1
9 1708
<ra********@gmail.comschrieb im Newsbeitrag
news:80**********************************@s8g2000p rg.googlegroups.com...
Hi,

If I include a ".h" file for multiple times, will it increase my
program size??
Unless you do things in these headers that should be done there, like
defining variable rather than just declaring them, no.
However, it's a good idea to prevent that from happening using header guards

#ifndef myheader_h
#define myheader_h
/* your header here */
....
#endif /* myheader_h */
Bye, Jojo
Dec 6 '07 #2
ra********@gmail.com writes:
If I include a ".h" file for multiple times, will it increase my
program size??
Normally, no. It might take longer to compile, though.
--
Ben Pfaff
http://benpfaff.org
Dec 6 '07 #3
Joachim Schmitz wrote:
<ra********@gmail.comschrieb im Newsbeitrag
news:80**********************************@s8g2000p rg.googlegroups.com...
>Hi,

If I include a ".h" file for multiple times, will it increase my
program size??
Unless you do things in these headers that should be done there, like
defining variable rather than just declaring them, no.
I think you mean "shouldn't be done". Also, if you define a variable in
a header and include it multiple times, it won't increase your code size
because your code will no longer compile...
However, it's a good idea to prevent that from happening using header guards

#ifndef myheader_h
#define myheader_h
/* your header here */
...
#endif /* myheader_h */
Quite.
Dec 6 '07 #4
"Philip Potter" <pg*@doc.ic.ac.ukschrieb im Newsbeitrag
news:fj**********@aioe.org...
Joachim Schmitz wrote:
><ra********@gmail.comschrieb im Newsbeitrag
news:80**********************************@s8g2000 prg.googlegroups.com...
>>Hi,

If I include a ".h" file for multiple times, will it increase my
program size??
>Unless you do things in these headers that should be done there, like
defining variable rather than just declaring them, no.

I think you mean "shouldn't be done".
Indeed. Fingers faster than brain, yet again...
Also, if you define a variable in a header and include it multiple times,
it won't increase your code size because your code will no longer
compile...
Unless it is included in everal modules

Bye, Jojo
Dec 6 '07 #5

"Philip Potter" <pg*@doc.ic.ac.ukwrote in message
news:fj**********@aioe.org...
Joachim Schmitz wrote:
>Unless you do things in these headers that should be done there, like
defining variable rather than just declaring them, no.

I think you mean "shouldn't be done". Also, if you define a variable in a
header and include it multiple times, it won't increase your code size
because your code will no longer compile...
You can make a variable static, so each includer has his own local copy.

This is seldom a good idea.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Dec 6 '07 #6
ra********@gmail.com wrote:
If I include a ".h" file for multiple times, will it increase my
program size??
Multiple times in the same compilation unit, or in different compilation
units?

It depends on the .h file. Typically not, for well-written .h files, but
of course it's possible to arrange otherwise:

fragment.h:

{ 17, 42 },

repeating.c:

static int silly[][2] =
{
#include "fragment.h"
#include "fragment.h"
#include "fragment.h"
#include "fragment.h"
#include "fragment.h"
#include "fragment.h"
};

Something like this can even be useful -- `fragment` can depend on a macro
which is #define'd and #undef'd and re-#define'd in `repeating`. But this
happens sufficiently infrequently that you do a sanity check if you come
across it (ie there may well be a better design).

--
Chris "still crazy after all these gears" Dollin

Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN

Dec 7 '07 #7
In article <fj**********@tadcaster.hpl.hp.com>,
Chris Dollin <ch**********@hp.comwrote:
>It depends on the .h file. Typically not, for well-written .h files, but
of course it's possible to arrange otherwise:

fragment.h:

{ 17, 42 },

repeating.c:

static int silly[][2] =
{
#include "fragment.h"
#include "fragment.h"
#include "fragment.h"
#include "fragment.h"
#include "fragment.h"
#include "fragment.h"
};

Something like this can even be useful -- `fragment` can depend on a macro
which is #define'd and #undef'd and re-#define'd in `repeating`. But this
happens sufficiently infrequently that you do a sanity check if you come
across it (ie there may well be a better design).
If you use something like this, I recommend not using the suffix ".h"
for the filename. Keep ".h" for real *h*eader files - that is, files
of declarations rather than miscellaneous bits of C.

-- Richard

--
:wq
Dec 7 '07 #8
On Dec 7, 5:33 pm, rich...@cogsci.ed.ac.uk (Richard Tobin) wrote:
In article <fjb89d$4g...@tadcaster.hpl.hp.com>,
Chris Dollin <chris.dol...@hp.comwrote:


It depends on the .h file. Typically not, for well-written .h files, but
of course it's possible to arrange otherwise:
fragment.h:
{ 17, 42 },
repeating.c:
static int silly[][2] =
{
#include "fragment.h"
#include "fragment.h"
#include "fragment.h"
#include "fragment.h"
#include "fragment.h"
#include "fragment.h"
};
Something like this can even be useful -- `fragment` can depend on a macro
which is #define'd and #undef'd and re-#define'd in `repeating`. But this
happens sufficiently infrequently that you do a sanity check if you come
across it (ie there may well be a better design).

If you use something like this, I recommend not using the suffix ".h"
for the filename. Keep ".h" for real *h*eader files - that is, files
of declarations rather than miscellaneous bits of C.

-- Richard

--
:wq- Hide quoted text -

- Show quoted text -
Hi,

Thanks for youre replies. MY situation is something like this:

test.h
--------
#define MACRO 1
void test();
extern int i;

test.c
-------
#include "test.h"
#include "test.h"

int i = 23;

void main()
{
printf("test..");
}

In this case, whether program size increases??

Regards
Satish.
Dec 7 '07 #9

<ra********@gmail.comschrieb im Newsbeitrag
news:69**********************************@i12g2000 prf.googlegroups.com...
Hi,

Thanks for youre replies. MY situation is something like this:

test.h
--------
#define MACRO 1
void test();
extern int i;

test.c
-------
#include "test.h"
#include "test.h"

int i = 23;

void main()
{
printf("test..");
}

In this case, whether program size increases??
No

Bye, Jojo
Dec 7 '07 #10

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

Similar topics

1
by: David Winter | last post by:
(Sorry - couldn't find a generic DocBook NG - I hope this is close enough.) I'm considering moving my documentation and translation business - which is currently done in proprietary formats such...
14
by: Fritz Foetzl | last post by:
I'm flummoxed. I'm a veteran C++ programmer from the Unix/Linux camp, trying to learn Visual C++. I'm trying to build a project in which I need to include one header in a couple of different files,...
6
by: techBoy | last post by:
I am looking for a tool that can scan my soyrce code and check if a header file gets included more then once in a sequece of compiled code. Can some one guide me to such a tool !!
3
by: fc2004 | last post by:
Hi, Is there any tools that could report where cyclic header dependency happens? this would be useful when working with a large project where tens or hundreds of headers files may form complex...
8
by: ewpatton | last post by:
I have a header that is shared among different CPP files for constants. When Microsoft Visual C++ links the .obj files, it complains that these names are all duplicates. How can I get it to realize...
6
by: Richard | last post by:
1. Are there any problems with having, for instance, POSIX's "open" function #defined more than once. In my case, these would be in different static libraries: #ifdef __cplusplus extern "C" {...
10
by: zfareed | last post by:
Similar problem to the previous post. I have created a project with about 7 files including 3 header files and 3 implementation files. I am getting a multiple definition error when compiling for...
2
by: max.giacometti | last post by:
Hi everybody! I am using lex and yacc to write a vhdl to systemc converter. Lex simply reads the input file and yacc implements grammar and translation. I'd like to be able to make yacc...
1
by: RajinCodingForum | last post by:
I have some idea but i am puzzled. As i understand, file inclusion problems like x includes y and y in turn includes x etc. can be avoided by #ifdef preprocessor checks. Can you please explain with...
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?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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,...

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.