R
ramsatishv
Hi,
If I include a ".h" file for multiple times, will it increase my
program size??
Regards
Ram.
If I include a ".h" file for multiple times, will it increase my
program size??
Regards
Ram.
Unless you do things in these headers that should be done there, likeHi,
If I include a ".h" file for multiple times, will it increase my
program size??
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 */
Indeed. Fingers faster than brain, yet again...Philip Potter said:I think you mean "shouldn't be done".
Unless it is included in everal modulesAlso, 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.Philip Potter said: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...
If I include a ".h" file for multiple times, will it increase my
program size??
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).
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
NoHi,
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??
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.