C Programming - C Preprocessor - Discussion

Discussion Forum : C Preprocessor - Yes / No Questions (Q.No. 7)
7.
Will it result in to an error if a header file is included twice?
Yes
No
It is compiler dependent.
Answer: Option
Explanation:
Unless the header file has taken care to ensure that if already included it doesn't get included again.

Turbo C, GCC compilers would take care of these problems, generate no error.
Discussion:
9 comments Page 1 of 1.

Nivetha said:   7 years ago
Please explain me the answer clearly.

Vjay said:   8 years ago
#define calc(a,b) (a*b)/(a-b)
main()
{
Int a=20,b=10;
Printf("%d", calc(a+4,b-2));
}

What will be the answer? Please tell me.

Gurunath said:   1 decade ago
We don't understand clearly.

George said:   1 decade ago
It depends in the header file. If there are inclusion guards, then it should be OK.

Eg:

#ifndef __STDIO_H__
#define __STDIO_H__
<contents>
#endif

Once the header is a called a second time, #ifndef __STDIO_H__ will evaluate to FALSE.

Onkar said:   1 decade ago
I didn't get it please explain it again in simple words.

Saravanan A said:   1 decade ago
Yes its very much dependent on the content. If only extern function declarations and extern variable declarations are there it will not be a issue. Only if some types are defined like structure - redefinition error will come. Or if a variable if defined which is a rare case though.

Pruthvi said:   1 decade ago
Can any one tel me what will b the error if we include an header file twice. ? as the linker will link to any of the headerfiles function then how the error comes. ?

Chetana said:   1 decade ago
Dont you think your explaination & Answer are differ. Please reply.

Tim said:   1 decade ago
Your answer depends on the CONTENTS of the header file. For example, a header file that is EMPTY can be included as many times as you like!

Post your comments here:

Your comments will be displayed after verification.