Difficulty: Easy
Correct Answer: It is compiler dependent.
Explanation:
Introduction / Context:
Headers are often included in multiple translation units or indirectly through other headers. This question probes understanding of include guards (#ifndef/#define/#endif) and their role in avoiding redefinition errors.
Given Data / Assumptions:
Concept / Approach:
Multiple inclusion does not inherently break compilation. If a header employs guards (or #pragma once) and only contains repeatable declarations, double inclusion is harmless. Without guards, duplicate definitions (for example, non-static objects or functions with multiple definitions) can cause errors. Some compilers diagnose more aggressively; others may allow benign redeclarations.
Step-by-Step Solution:
Case 1: Guarded header → compiling succeeds even if included twice.Case 2: Unguarded, only declarations → may still compile, but fragile.Case 3: Unguarded with definitions → likely multiple-definition error at compile or link time.
Verification / Alternative check:
Add #ifndef H_H / #define H_H / #endif to a header; include it twice and confirm a single effective inclusion.
Why Other Options Are Wrong:
“Always yes” and “Always no” overgeneralize. Platform-limited claims (Linux or system headers only) are incorrect.
Common Pitfalls:
Placing non-inline function definitions or global objects in headers without guards; forgetting that #pragma once is non-standard but widely supported.
Final Answer:
It is compiler dependent.
Discussion & Comments