Hi,
If I include a ".h" file for multiple times, will it increase my
program size??
Regards
Ram. 9 1722
<ra********@gma il.comschrieb im Newsbeitrag
news:80******** *************** ***********@s8g 2000prg.googleg roups.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
Joachim Schmitz wrote:
<ra********@gma il.comschrieb im Newsbeitrag
news:80******** *************** ***********@s8g 2000prg.googleg roups.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.
"Philip Potter" <pg*@doc.ic.ac. ukschrieb im Newsbeitrag
news:fj******** **@aioe.org...
Joachim Schmitz wrote:
><ra********@gm ail.comschrieb im Newsbeitrag news:80******* *************** ************@s8 g2000prg.google groups.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
"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 ra********@gmai l.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
In article <fj**********@t adcaster.hpl.hp .com>,
Chris Dollin <ch**********@h p.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
On Dec 7, 5:33 pm, rich...@cogsci. ed.ac.uk (Richard Tobin) wrote:
In article <fjb89d$4g...@t adcaster.hpl.hp .com>,
Chris Dollin <chris.dol...@h p.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.
<ra********@gma il.comschrieb im Newsbeitrag
news:69******** *************** ***********@i12 g2000prf.google groups.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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 as FrameMaker,
Word and XPress - to a system centered around DocBook. I'm currently
reading "DocBook - The Definitive Guide", but I'll need a few answers
ASAP ... So maybe a kind soul could give me at least a few hints.
|
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, but the
classic multiple inclusion problem is biting me hard. The
#ifndef..#define..#endif method doesn't seem to be working, although
all the documentation I've read indicates that it should.
As a small example, I have an empty console...
|
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 !!
|
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 inclusion
relationships.
Another question I have is how to solve this dependency when "typedef"
is used. usually we can use forward declaration like "struc A; " to
solve references like "struct A* p". But in many places we have
|
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 that these are
coming from the same header and refer to the same things instead of
making two different copies?
| |
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" {
#endif
#define open myOpenFunction1
|
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 one specific
file of class. I have checked that if there is more than one
allocation of storage for identifiers, this error arises. But I don't
see where the problem lies. Any suggestions?
<code>
//ItemType.h
#ifndef ItemType_hpp // I was...
|
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 able to command lex to stop reading
the current file and starting reading another file, when the inclusion
syntax is reached.
|
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 detailed examples on scenarios which result in Multiple File Inclusion problems?
The best way i employ is :
Let us say we have 4 files:
x.h y.h
x.c y.c
x.h includes y.h.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |