Difficulty: Easy
Correct Answer: A preprocessing fatal error is generated and translation stops (for example, fatal error: file not found)
Explanation:
Given data
#include
directive to include a header.
Concept / Approach
During translation phase 4, the preprocessor must locate each header named by #include
. If the search fails, the implementation is required to issue a diagnostic and cannot continue normal translation of that unit.Both forms, #include "file.h"
and #include
, ultimately require that the file be found in the applicable search paths; otherwise a fatal error is produced.
Step-by-step reasoning
1) The preprocessor reads #include
and initiates a search based on the directive form (quotes usually search the current directory first, then system paths; angle brackets search system paths).2) If the header is not found in any searched directory, the preprocessor emits a fatal error diagnostic (commonly shown as “fatal error: file not found”).3) The translation unit cannot be produced; the build halts for that file at preprocessing time.
Why other options are incorrect
Option B: A mere warning would allow continuation, but the standard behavior is a fatal error when a required header is missing.Option C: A linker error occurs much later and only after successful compilation; here preprocessing fails before compilation.Option D: Silently skipping the header would risk undefined compilation results; conforming preprocessors do not do this.
Common pitfalls
Final Answer
A preprocessing fatal error is generated and translation stops.
Discussion & Comments