Machine-translated by Google. Questions are authored in English.
Top

Discussion

Will it result in to an error if a header file is included twice?

  • A.Yes
  • B.No
  • C.It is compiler dependent.

Answer: C

Correct answer: It is compiler dependent.

It depends on what the header contains and how strictly the compiler treats a repeat. A header with an include guard is harmless however often it is named, and repeating a macro definition or a function prototype identically is allowed. But a header that defines a type or a variable will, on a second inclusion, produce a duplicate definition - and older compilers reject some repeats that newer ones tolerate. Guarding the header removes the question entirely.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.