Home » C Programming » C Preprocessor

C/C++ preprocessor behavior: What happens when a header named in an #include directive cannot be found in the include search paths? Assume a standard, conforming toolchain and normal search rules for both #include "file.h" and #include <file.h>. Choose the correct outcome.

Difficulty: Easy

Correct Answer: A preprocessing fatal error is generated and translation stops (for example, fatal error: file not found)

Explanation:


Given data

  • A source file uses an #include directive to include a header.
  • The named header is not present at any location that the preprocessor searches.


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

  • Confusing warning vs fatal error; missing headers stop preprocessing.
  • Assuming angle brackets vs quotes change the requirement to find the file; both must locate a real file somewhere in the search sequence.


Final Answer
A preprocessing fatal error is generated and translation stops.

← Previous Question Next Question→

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion